LOJ#4. Quine

题目描述

写一个程序,使其能输出自己的源代码。
代码中必须至少包含十个可见字符。

题解

这题好神仙啊。。。
因为不会骚操作所以就写了一个通用的做法:
用一个字符串数组记录下除去该字符串的代码
然后依次输出,输出到字符串数组时就再输出一遍(要加上引号和逗号并特判最后一行)
最后把剩下的输出完

code

#include <bits/stdc++.h>
#include <iostream>
#define fo(a,b,c) for (a=b; a<=c; a++)
using namespace std;
string a[17]={
"#include <bits/stdc++.h>",
"#include <iostream>",
"#define fo(a,b,c) for (a=b; a<=c; a++)",
"using namespace std;",
"string a[17]={",
"};",
"int i;",
"int main()",
"{",
"fo(i,0,4)",
"cout<<a[i]<<endl;",
"fo(i,0,15)",
"cout<<char(34)<<a[i]<<char(34)<<char(44)<<endl;",
"cout<<char(34)<<a[16]<<char(34)<<endl;",
"fo(i,5,16)",
"cout<<a[i]<<endl;",
"}"
};
int i;
int main()
{
fo(i,0,4)
cout<<a[i]<<endl;
fo(i,0,15)
cout<<char(34)<<a[i]<<char(34)<<char(44)<<endl;
cout<<char(34)<<a[16]<<char(34)<<endl;
fo(i,5,16)
cout<<a[i]<<endl;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值