写在前面
- 实现思路
- vector容器封装表情结果,
vector<vector<string>> face;
- 循环字符读入
- 循环字符输出(非法示例输出)
- 问题点
- “Are you kidding me? @/@”的’\’是转义字符,想要输出’\’就要用’\’表示~
- 题目简单,15分钟a题
测试用例
input:
[╮][╭][o][~\][/~] [<][>]
[╯][╰][^][-][=][>][<][@][⊙]
[Д][▽][_][ε][^] ...
4
1 1 2 2 2
6 8 1 5 5
3 3 4 3 3
2 10 3 9 3
output:
╮(╯▽╰)╭
<(@Д=)/~
o(^ε^)o
Are you kidding me? @\/@
ac代码
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<vector<string>> face;
for(int i=0; i<3; i++)
{
vector<string> strs;
string units;
char ch;
while(1)
{
scanf("%c", &ch);
if(ch == '\n') break;
if((ch==' ') || (ch=='['))
continue;
if(ch==']')
{
strs.push_back(units);
units = "";
}
else
units += ch;
}
face.push_back(strs);
}
int n;
scanf("%d", &n);
for(int i=0; i<n; i++)
{
int a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
if(a > face[0].size() || b > face[1].size() || c > face[2].size() || d > face[1].size() || e > face[0].size() || a < 1 || b < 1 || c < 1 || d < 1 || e < 1)
{
printf("Are you kidding me? @\\/@\n");
continue;
}
cout << face[0][a-1] << "(" << face[1][b-1] << face[2][c-1] << face[1][d-1] << ")" << face[0][e-1] << endl;
}
return 0;
}
学习代码
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<vector<string> > v;
for(int i = 0; i < 3; i++) {
string s;
getline(cin, s);
vector<string> row;
int j = 0, k = 0;
while(j < s.length()) {
if(s[j] == '[') {
while(k++ < s.length()) {
if(s[k] == ']') {
row.push_back(s.substr(j+1, k-j-1));
break;
}
}
}
j++;
}
v.push_back(row);
}
int n;
cin >> n;
for(int i = 0; i < n; i++) {
int a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
if(a > v[0].size() || b > v[1].size() || c > v[2].size() || d > v[1].size() || e > v[0].size() || a < 1 || b < 1 || c < 1 || d < 1 || e < 1) {
cout << "Are you kidding me? @\\/@" << endl;
continue;
}
cout << v[0][a-1] << "(" << v[1][b-1] << v[2][c-1] << v[1][d-1] << ")" << v[0][e-1] << endl;
}
return 0;
}