- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个长期的思想实验,关于如何编写一行 C++ 代码,其中包含最大数量的唯一保留字。在此挑战中,您可以根据需要重复使用关键字,但重要的是您使用的独特关键字的数量。例如,如果你写
void MyFunction(int, int, int, int);
int 有四个实例,但上面这行得分为 2,因为它只有两个唯一关键字(即 void
和 int
)。不过,这一行
void MyFunction(int, double, short, long);
它的五个保留字得分为 5。
到目前为止,我能想到的最好的是
export template <typename T, class C>
inline void DiabolicalFunc (int, char, short,
long, double, signed,
unsigned, bool, float,
wchar_t, const int,
volatile int,
enum MyEnum,
void* (*)(size_t) = &(operator new),
void (*)(void*) = &(operator delete),
int = const_cast<int*>(static_cast<const int *>(reinterpret_cast<int*>(0))),
void* = dynamic_cast<void*>(reinterpret_cast<ios_base*>(0)),
bool = true, bool = false, int = sizeof(int),
const std::type_info& = typeid(int),
struct MyStruct = MyStruct(), union MyUnion = MyUnion(),
int = 0 and 0,
int = 0 bitand 0,
int = 0 bitor 0,
int = compl 0,
int = not 0,
int = 0 not_eq 0,
int = 0 or 0,
int = 0 xor 0) throw();
其中包含多达 39 个保留字。不过,它假设您在声明之前已经定义了 enum MyEnum
、struct MyStruct
和 union MyUnion
。是的,如果您在使用它之前设置了适当的类型,它会在 g++
中编译(尽管它会给出关于 export
的警告。)
我很好奇是否有人看到任何方法可以将更多独特的关键字塞进一行代码中。有人可以超越我的榜样吗?或者想办法让它变得更加邪恶?
我知道 C++ 是自由形式的,因此“代码行”并不是衡量结构的真正好方法,但我认为我们可以对这意味着什么做出合理的解释。
编辑: 刚刚在函数末尾添加了 throw()
以在其中获得一个关键字。
最佳答案
你说一行C++代码?
// asm auto bool break case catch char class const ...
我开玩笑,我开玩笑。
关于C++ 挑战 : Maximum unique reserved words in one logical line of code?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5014353/
我想得到 id a b c -------------------- 1 1 100 90 6 2 50 100 ...来自: id a
让我们看看,我有这段将 NFA 自动转换为 DFA 的代码;这是我编写的;我发现了一个“bug”; printf()指令 这意味着像这样“printf("",X); ”以防止出现错误 没有要在屏幕上打
我有一些文本图像,但它们是弯曲的,呈圆形或波浪形。我需要把它们弄直。我尝试使用OCR提取文本,但是它们效率低下,需要直接的图像。 我附上测试图片: 我需要覆盖这两个最小区域。 请建议一些路径或使用
data1=data.frame("StudentID"=c(1,1,1,2,2,2,2,3,3,3,3), "Class"=c(1,1,1,1,1,1,1,2,2,2,2),
我的问题已在 java draw line as the mouse is moved 中提到过然而,我对这本书的了解还不够深入,无法涵盖 JPanels、JFrames 和 Points,正如提出这
这是我上一个问题 here. 的后续问题那里发布的答案实际上不起作用。所以这就是挑战。您将获得以下代码(假设包含 jQuery): $("input").val(**YOUR PHP /
以下是C语言中链表的语法,部分内容 struct tag-name { type member1; type member2; ....... ....... struc
我面临以下挑战性问题: There are a circle of 100 baskets in a room; the baskets are numbered in sequence from 1
我有一个这样的结构: public struct MyStruct { public string Name; public bool Process; } 我有一个这样的
假设我有: var directions = [ "name", "start_address", "end_address", "order_date" ]; 我正在尝试找到一种巧妙、快速的方法来将
我正在用 Javascript 重做 Project Euler 挑战。任务是获取最大的回文数( https://projecteuler.net/problem=4 )。现在我得到以下代码: var
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
第一问:有没有可能有一个不可见的矩形? 问题 2:是否可以在方法上调用方法?见下文。 var canvas = document.getElementById("canvas"); var ctx =
问题: 给定一串数字,计算是任何回文的字谜的子词(一致的子序列)的数量。 例子: 对于输入字符串“02002”,结果应该是 11,即: “0”、“2”、“0”、“0”、“2”、“00”、“020”、“
用户A-用户B-用户C-用户D-用户F 用'-'连接的用户互相认识。 我需要一个算法来完成这两项任务: 计算从UserX到UserY的路径 对于 UserX,计算距离不超过 3 步的所有用户。 有没有
根据我的教授介绍。对于数据库理论,没有任何例子可以说明这种情况何时会出现,考虑到它是理论的特定部分,这似乎有点奇怪。 我正在寻找的只是一个示例关系,它是第 4 范式并且可以执行第 5 范式分解。或者(
给定任务sameEnds来自 CodingBat: 给定一个字符串,返回出现在字符串开头和结尾且不重叠的最长子字符串。例如,sameEnds("abXab") 是 "ab"。 sameEnds("ab
在我的 welcome#index 页面上,有一个按钮可以远程(或者我应该说异步)为 Article 编写新的 Comment ),使用 AJAX。 它工作得很好,只是当使用rails迭代一篇文章时,
希望每个人都有美好的一天。 这是我在 Stackoverflow 上发表的第一篇文章! 我刚刚完成了 Codeacademy 上的 javascript 类(class),并且也阅读了几本相关书籍。现
挑战是删除数字末尾的零。两个数字内的零是可以的。例如: 14000 == 14 //all end zeros removed 10300 == 103 // all end zeros remove
我是一名优秀的程序员,十分优秀!