织梦行云

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

The C implementation is as follows:

#include<stdio.h>
int main(){printf("#include<stdio.h>\n");char *p="int main(){printf(%c#include<stdio.h>%cn%c);char *p=%c%s%c;printf(p,34,92,34,34,p,34);return 0;}";printf(p,34,92,34,34,p,34);return 0;}

The trick here is the string 'p'. In order to print the string itself, we use a '%s' in the string. This character split the string into two parts. The first part is:

int main(){printf("#include<stdio.h>\n");char *p="

And the second is:

";printf(p,34,92,34,34,p,34);return 0;}

And the character '%s' represents the string itself. With the help of C-function 'printf', we then can easily obtain the solution.

 

Moreover, I've seen lots of other solutions on the internet. Some of them just use file operations to print the source code file to the screen. It is really bull shit. What if source code file is forbidden?

 

The other solutions just provide a pile of unrecognizable characters. In my opinion, these code is not beautiful enougth, for they destroy the beauty of programming. So if u find any better solutions, please contact me. ^_^

posted on 2010-03-15 00:12  BloodElf  阅读(132)  评论(0编辑  收藏  举报