码迷,mamicode.com
首页 > 其他好文 > 详细

一道有趣的签到题

时间:2019-10-07 00:42:48      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:blog   href   col   %s   字符串   有趣   osc   程序   attach   

 

题目链接

题目描述

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

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

输入格式

输入文件为空。

输出格式

你的源代码。

 


 

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

 

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

#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
*/

 

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

 

一道有趣的签到题

标签:blog   href   col   %s   字符串   有趣   osc   程序   attach   

原文地址:https://www.cnblogs.com/kkkek/p/11629001.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!