#include<string>
#include<iostream>
#include<vector>
using namespace std;
int main() {
string s1;
vector<vector<string> >V(3);
for (int i = 0; i < 3; i++) {
getline(cin, s1);
while (s1.find('[') != string::npos) {
V[i].push_back(s1.substr(s1.find_first_of('[') + 1, s1.find_first_of(']') - s1.find_first_of('[') - 1));
if (V[i][V[i].size() - 1] == "") { V[i].pop_back(); V[i].push_back(" "); }
s1.erase(s1.begin() + s1.find_first_of('['), s1.begin() + s1.find_first_of(']') + 1);
}
}
int n, tmp1, tmp2, tmp3, tmp4, tmp5;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d %d %d %d", &tmp1, &tmp2, &tmp3, &tmp4, &tmp5);
if (tmp1 > V[0].size() || tmp2 > V[1].size() || tmp3 > V[2].size() ||
tmp4 > V[1].size() || tmp5 > V[0].size()||tmp1<1||tmp2<1||tmp3<1||tmp4<1||tmp5<1) {
printf("Are you kidding me? @\\/@\n"); continue;
}
printf("%s(%s%s%s)%s\n", V[0][tmp1 - 1].c_str(), V[1][tmp2 - 1].c_str(), V[2][tmp3 - 1].c_str(), V[1][tmp4 - 1].c_str(), V[0][tmp5 - 1].c_str());
}
return 0;
}
先上代码再分析。
这个题难点在于:
①:对数据读入的处理,如何把【】去除,并获取正确内容,这是很关键。
②:测试点对越界测试,测试点2是对输入的序号大于了可以选的眼,口,鼻的个数,测试点1的对下界,就是测试点输入了0号口,但是最小只存在1号口,不对其进行处理,就会导致段错误。