首先輸入就巨亂,一下子中間多一個空格,一下子後面多一個省略號,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;
}