没——问题 发表于 2009-4-15 17:00:05

打印自身

http://wxx.cs.hit.edu.cn/?p=138
Author: Unknown (from The Jargon File)
Notes: The first several examples are variations of the standard one-liner C quines.
main(){char *c="main(){char *c=%c%s%c;printf(c,34,c,34);}";printf(c,3
4,c,34);}

Author: Joe Miller
Notes: This causes some warnings but should compile fine.
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}

Author: John Burger, David Brill, Filip Machi
main(){char q=34,n=10,*a="main(){char q=34,n=10,*a=%c%s%c;printf(a,q,a,q,n);}%c";printf(a,q,a,q,n);}

Author: Unknown
main(){char*a="main(){char*a=%c%s%c;int b='%c';printf(a,b,a,b,b);}";int b='"';printf(a,b,a,b,b);}

Author: Dario Dariol
main(a,b){a="main(a,b){a=%c%s%c;b='%c'; printf(a,b,a,b,b);}";b='"';printf(a,b,a,b,b);}

Author: Dario Dariol
main(a){printf(a="main(a){printf(a=%c%s%c,34,a,34);}",34,a,34);}

Author: Unknown
char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}"; main(){printf(p,34,p,34);}

Author: Dario Dariol
main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}";printf(a,34,a,34);}

Author: Unknown
char f[] = "char f[] =%c%c%s%c;%cmain() {printf(f,10,34,f,34,10,10);}%c";   
main() {printf(f,10,34,f,34,10,10);}

Author: Thad Smith
Notes: The author claims that this one is strict ANSI.
#include<stdio.h>
main(){char*c="\\\"#include<stdio.h>%cmain(){char*c=%c%c%c%.102s%cn%c
;printf(c+2,c,c,*c,*c,c,*c,c);exit(0);}\n";printf(c+2,c[10
2],c,*c,*c,c,*c,c);exit(0);}

Author: Torben Mogensen
char *a="\\\"char *a=%c%.1s%.1s%.71s%.1sn%c;main() {printf(a+2,a,a,a,a,a,a);}\n"; main(){printf(a+2,a,a,a,a,a,a);}

Author: Joe Miller
#define T(a) main(){printf(a,#a);}
T("#define T(a) main(){printf(a,#a);}\nT(%s)")

Author: Erkki Ruohtula (eru@tnso04.tele.nokia.fi)
#define n(v,w) v(#w"\nn("#v","#w")");}
n(main(){puts,#define n(v,w) v(#w"\nn("#v","#w")");})

Author: Paul Hsieh
#define X(Y) main(){printf("#define X(Y) %s\nX(%s)\n",#Y,#Y);}
X(main(){printf("#define X(Y) %s\nX(%s)\n",#Y,#Y);})

zgg___ 发表于 2009-4-17 14:05:16

厉害呀。

xenium9 发表于 2009-4-19 20:05:08

The Quine Page

http://www.nyx.net/~gthompso/quine.htm

xenium9 发表于 2009-4-19 20:08:47

打印自身的C#代码

class C
{
const string s = @"class C
{{
const string s = @{1}{0}{1};
static void Main()
{{
    System.Console.WriteLine(s,s,'\u0022');
}}
}}";
static void Main()
{
    System.Console.WriteLine(s,s,'\u0022');
}
}

xenium9 发表于 2009-4-19 20:15:25

打印自身的C#代码(单行版本)

class C{const string s=@"class C{{const string s=@{1}{0}{1};static void Main(){{System.Console.WriteLine(s,s,'\u0022');}}}}";static void Main(){System.Console.WriteLine(s,s,'\u0022');}}

winxos 发表于 2009-4-24 17:37:03

原帖由 没——问题 于 2009-4-15 17:00 发表 http://bbs.emath.ac.cn/images/common/back.gif
http://wxx.cs.hit.edu.cn/?p=138
Author: Unknown (from The Jargon File)
Notes: The first several examples are variations of the standard one-liner C quines.
main(){char *c="main(){char *c=%c%s%c;pri ...
printf中的34的参数是什么意思?:Q:

没——问题 发表于 2009-4-25 02:50:20

main(){char *a="%c";printf(a,91);}
此处a就是%c,91就是[的ascii

winxos 发表于 2009-4-25 06:52:36

原帖由 没——问题 于 2009-4-25 02:50 发表 http://bbs.emath.ac.cn/images/common/back.gif
main(){char *a="%c";printf(a,91);}
此处a就是%c,91就是[的ascii
原来是ASCII码,不知道这种程序存在什么难点呢?

winxos 发表于 2009-4-25 23:39:42

原帖由 winxos 于 2009-4-25 06:52 发表 http://bbs.emath.ac.cn/images/common/back.gif

原来是ASCII码,不知道这种程序存在什么难点呢?
我错了。

crush 发表于 2009-8-28 19:24:28

没看懂啊~~
页: [1] 2
查看完整版本: 打印自身