前情提要:我的马蜂
前言
众所周知,如果我们打比赛时一不小心点开了AI,又一不小心让AI生成了代码,又一不小心提交了AI生成的代码,我们就会获得棕名。
这个不公平的机制肯定让许多人恼火,所以「代码格式化器」因此诞生了。
Part1:功能描述
我们希望做出的程序可以用来格式化代码。也就是说,我们输入一串代码,程序就可以输出格式化后的对应代码。
Part2:输入输出
我们可以考虑用vector<string>:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string inp = "You have no egg!";
vector<string>code;
while(inp != "CCF_has_no_egg")
{
cin >> inp;
code.push_back(inp);
}
for(int i = 0;i < code.size();i++)
{
cout << code[i];
}
return 0;
}只需在最后加上CCF_has_no_egg即可。
注:其实可以实现自动结束,但是感觉报复一下CCF更好
但是我们注意到输出胡成了一团。
所以可以改成:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string inp = "You have no egg!";
vector<string>code;
while(inp != "CCF_has_no_egg")
{
cin >> inp;
code.push_back(inp);
}
for(int i = 0;i < code.size();i++)
{
cout << code[i];
if(code[i][code[i].length() - 1] == ';' || code[i][code[i].length() - 1] == ')' || code[i][code[i].length() - 1] == '>'|| code[i][code[i].length() - 1] == '{'|| code[i][code[i].length() - 1] == '}')
{
cout << "\n";
}
else
{
cout << " ";
}
}
return 0;
}