Output as its own C program
Crazy FT.
Http://acm.tongji.edu.cn/people/ps/showproblem.php? Problem_id = 1072
ACM has such a question!
So I searched on google, and there was ......
The skills of this type of program are the use of the string definition for the ASCII value 34 and 10, that is, the quotation marks and carriage return characters:
1.
Char * f = "main () {putchar ('C'); putchar ('H'); putchar ('A'); putchar ('R '); putchar ('*'); putchar ('F'); putchar ('='); putchar (34); printf (f); putchar (34); putchar ('; '); putchar (10); printf (f); putchar (10) ;}"; main () {putchar ('C'); putchar ('H '); putchar ('A'); putchar ('R ');
Putchar ('*'); putchar ('F'); putchar ('='); putchar (34); printf (f); putchar (34); putchar ('; '); putchar (10); printf (f); putchar (10 );}
2.
Char * f = "char * f =; main () {f [7] = 0; printf (f); putchar (34); f [7] = ';'; printf (f); putchar (34); f [8] = 0; printf (& f [7]); f [8] = 'M'; putchar (10 ); printf (& f [8]); putchar (10) ;}"; main () {f [7] = 0; printf (f); putchar (34 ); f [7] = '; printf (f); putchar (34); f [8] = 0; printf (& f [7]); f [8] = 'M'; putchar (10); printf (& f [8]); putchar (10 );}
3.
Char * f = "char * f = % c % s % c; % cmain () {printf (f, 34, f, 34,10, 10);} % c ";
Main () {printf (f, 34, f, 34,10, 10 );}
4.
Char a = '"'; char B = '/N'; char c =' // '; char * f =" char a =' % C '; char B = '% cn'; char c =' % c % C'; % cchar * f = % c % s % c; % cmain () {& printf (f, a, c, B, a, f, a, B, B) ;}% c "; main () {printf (f, a, c, c, c, B, a, f, a, B, B );}
5.
Char * lines [] = {"char * lines [] = {", "% c % s % c", "0};", "main () {"," int idx; "," puts (lines [0]); "," for (idx = 0; lines [idx]! = 0; idx ++) {"," printf (lines [1], 34, lines [idx], 34, ',', 10 );",
"}", "Puts (lines [2]);", "for (idx = 3; lines [idx]! = 0; idx ++) {"," puts (lines [idx]); ","} ","} ", 0 };
Main () {int idx; puts (lines [0]); for (idx = 0; lines [idx]! = 0; idx ++) {printf (lines [1], 34, lines [idx], 34, ',', 10);} puts (lines [2]); for (idx = 3; lines [idx]! = 0; idx ++) {puts (lines [idx]) ;}}
I picked the simplest one. After reading this, I modified it:
# Include <stdio. h>
Char * f = "# include <stdio. h> % cchar * f = % c % s % c; % cint main () {printf (f, 10, 34, f, 34,10, 10); return 0 ;} % c ";
Int main () {printf (f, 10, 34, f, 34, 10, 10); return 0 ;}
Haha, AC, but be careful when sticking it to the Submit box. Don't miss the last carriage return.