3 回答

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊
編譯時(shí)間遞歸!:P
#include <iostream>
template<int N>
struct NumberGeneration{
static void out(std::ostream& os)
{
NumberGeneration<N-1>::out(os);
os << N << std::endl;
}
};
template<>
struct NumberGeneration<1>{
static void out(std::ostream& os)
{
os << 1 << std::endl;
}
};
int main(){
NumberGeneration<1000>::out(std::cout);
}

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個(gè)贊
這實(shí)際上是編譯為沒有任何條件的程序集:
#include <stdio.h>
#include <stdlib.h>
void main(int j) {
printf("%d\n", j);
(&main + (&exit - &main)*(j/1000))(j+1);
}
編輯:添加了“&”,因此它將考慮地址,從而避免了指針錯(cuò)誤。
標(biāo)準(zhǔn)C中的上述版本,因?yàn)樗灰蕾囉诤瘮?shù)指針的算術(shù)運(yùn)算:
#include <stdio.h>
#include <stdlib.h>
void f(int j)
{
static void (*const ft[2])(int) = { f, exit };
printf("%d\n", j);
ft[j/1000](j + 1);
}
int main(int argc, char *argv[])
{
f(1);
}

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊
#include <stdio.h>
int i = 0;
p() { printf("%d\n", ++i); }
a() { p();p();p();p();p(); }
b() { a();a();a();a();a(); }
c() { b();b();b();b();b(); }
main() { c();c();c();c();c();c();c();c(); return 0; }
我很驚訝似乎沒有人發(fā)布此消息-我認(rèn)為這是最明顯的方法。 1000 = 5*5*5*8.
- 3 回答
- 0 關(guān)注
- 593 瀏覽
添加回答
舉報(bào)