无聊写的奇怪代码(2)

是这样的……

今天我考试的时候,闲的无聊,就开始写一串无聊代码

 1 #include<cstdio>
 2 using namespace std;
 3 int main()
 4 {
 5     freopen("1.in","r",stdin);
 6     freopen("1.out","w",stdout);
 7     #include<cstdio>
 8     using namespace std;
 9     int main()
10     {
11         freopen("2.in","r",stdin);
12         freopen("2.out","w",stdout);
13         return 2;
14     }
15     return 1;
16 }

就是这个一个套一个的程序……后来层数越来越多了,觉得手打太累,就写了一个小程序帮我输出这玩意

 1 #include<cstdio>
 2 using namespace std;
 3 int m;
 4 void pk(int n)
 5 {
 6     if(n == 0)    return;
 7     for(int i = 1;i <= n;i++)    printf("    ");
 8 }
 9 void p(int n)
10 {
11     if(n == m + 1)    return;
12     pk(n - 1);
13     printf("#include<cstdio>\n");
14     pk(n - 1);
15     printf("using namespace std;\n");
16     pk(n - 1);
17     printf("int main()\n");
18     pk(n - 1);
19     printf("{\n");
20     pk(n);
21     printf("freopen(\"");
22     printf("%d",n);
23     printf(".in\",\"r\",stdin);\n");
24     pk(n);
25     printf("freopen(\"");
26     printf("%d",n);
27     printf(".out\",\"w\",stdout);\n");
28     p(n + 1);
29     pk(n);
30     printf("return ");
31     printf("%d",n);
32     printf(";\n");
33     pk(n - 1);
34     printf("}\n");
35 }
36 int main()
37 {
38     freopen("hhh.out","w",stdout);
39     scanf("%d",&m);
40     p(1);
41     return 0;
42 }

相信有点c艹基础的人都能看懂

这是输入n = 5的结果

 1 #include<cstdio>
 2 using namespace std;
 3 int main()
 4 {
 5     freopen("1.in","r",stdin);
 6     freopen("1.out","w",stdout);
 7     #include<cstdio>
 8     using namespace std;
 9     int main()
10     {
11         freopen("2.in","r",stdin);
12         freopen("2.out","w",stdout);
13         #include<cstdio>
14         using namespace std;
15         int main()
16         {
17             freopen("3.in","r",stdin);
18             freopen("3.out","w",stdout);
19             #include<cstdio>
20             using namespace std;
21             int main()
22             {
23                 freopen("4.in","r",stdin);
24                 freopen("4.out","w",stdout);
25                 #include<cstdio>
26                 using namespace std;
27                 int main()
28                 {
29                     freopen("5.in","r",stdin);
30                     freopen("5.out","w",stdout);
31                     return 5;
32                 }
33                 return 4;
34             }
35             return 3;
36         }
37         return 2;
38     }
39     return 1;
40 }

然后我又试了一下n = 100……

这个建议自己试一下

posted on 2018-03-13 20:31  bb机  阅读(207)  评论(0编辑  收藏  举报

导航