一道有趣的签到题

题目链接

题目描述

写一个程序,使其能输出自己的源代码。

代码中必须至少包含十个可见字符。

输入格式

输入文件为空。

输出格式

你的源代码。


从来没想过还可以这么玩φ(゜▽゜*)♪

看着别人的题解写了一份代码:

#include<bits/stdc++.h>
#define kk(x) #x
using namespace std;
char s[]=kk(int main(){puts("#include<bits/stdc++.h>");puts("#define kk(x) #x");puts("using namespace std;");printf("char s[]=kk(");printf("%s",s);puts(");");puts(s);});
int main(){puts("#include<bits/stdc++.h>");puts("#define kk(x) #x");puts("using namespace std;");printf("char s[]=kk(");printf("%s",s);puts(");");puts(s);}

然后了解了一个以前不知道的知识点:C++#号的使用

1,#     字符串化 

2,##   连接字符串

3,#@  字符化(据说gcc编译器不行,微软特有)

#include<cstdio>
#define k(x) #x
#define kk(x) num##x
int main()
{
    printf(k(=-=)"\n");
    int numy=7;
    int t=kk(y);
    char b;
    printf("%d",t);
}
/*
输出:
=-=
7
*/

在这道题用#代替引号可以避免引用引号的一些麻烦

猜你喜欢

转载自www.cnblogs.com/kkkek/p/11629001.html