首先输入就巨乱,一下子中间多一个空格,一下子后面多一个省略号,wtf???
然后就来说一下巨坑:
- 最后输出的“Are you kidding me? @/@”你以为简单吗,其实中间藏了一个陷阱,有个转义字符,所以要加上一个\
- 手和脸之间有括号!眼瞎了我真是!
- 输入的数字不合理,从1开始,注意!! !输入0或者复数也是错误!! 真的服了
剩下的应该没啥坑了,因为有空格我用的是getchar来输入,感觉用起来比getline方便一丢丢,直接上代码:
// pta1052.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include <string>
using namespace std;
int main()
{
/*string ok;
getline(cin, ok);
cout << ok << endl;
return 0;*/
string jihe[3][11];
string* output;
int count[3] = { 0 };
int num;
for (int i = 0; i < 3; i++) { // 输入
int index = 0;
while (true) {
char temp = getchar();
if (temp == '[') {
count[i]++;
}
else if (temp == ']') {
index++;
}
else if (temp == 10) {
break;
}
else {
if (temp == ' ') {
continue;
}
//cout << temp << endl;
jihe[i][index] = jihe[i][index] + temp;
}
}
}
cin >> num;
output = new string[num];
for (int i = 0; i < num; i++) { // 处理输出
int flag = 0;
for (int m = 0; m < 5; m++) {
int ind;
cin >> ind;
if (ind < 1) {
flag = 1;
}
if (m < 3) {
//cout << count[m] << "ind: " << ind << endl;
if (ind > count[m]) {
flag = 1;
}
else {
output[i] = output[i] + jihe[m][ind - 1];
}
if (m == 0) {
output[i] = output[i] + "(";
}
}
else {
//cout << count[4 - m] << "ind2: " << ind << endl;
if (ind > count[4 - m]) {
flag = 1;
}
else {
output[i] = output[i] + jihe[4 - m][ind - 1];
}
if (m == 3) {
output[i] = output[i] + ")";
}
}
}
if (flag == 1) {
output[i] = "Are you kidding me? @\\/@"; // 注意转义
}
}
for (int i = 0; i < num; i++) {
if (i < num - 1) {
cout << output[i] << endl;
}
else {
cout << output[i];
}
}
return 0;
}