PAT 1052 賣個萌 (字串 難度2) - 詳細題解
阿新 • • 發佈:2019-01-14
題本身並不是很難, 只是其中涉及的知識, 如果學習時候不細心的話…還真不一定知道
比如題上的這些特殊字元, 不能夠用一個char來存, 必須用char陣列或者是string來存
主要就是輸入有點麻煩, 但語言用熟練的話也就好了
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef long long LL;
const LL maxn = 8;
int main()
{
vector<vector<string> > organ; //一個特殊字元視為一個字串
for(int i = 0; i < 3; i++){
string input;
vector<string> curRow;
getline(cin, input);
for(int j = 0, k = 0; j < input.length(); j++){
if(input[j]=='['){
while(k++ < input.length()) //向後遍歷提取字元
if(input[k] == ']'){
curRow.push_back(input.substr(j+1, k-j-1));
break ;
}
}
}
organ.push_back(curRow); //當前行提取出的字元存入
}
int k, q[12];
cin >> k;
for(int i = 0; i < k; i++){
for(int j = 1; j <= 5; j++)
cin >> q[j];
if(q[1]>organ[0].size() || q[5]>organ[0].size() || q[2]>organ[1].size() || q[4]>organ[1].size() || q[3]>organ[2].size()
|| q[1]<1 || q[2]<1 || q[3]<1 || q[4]<1 || q[5]<1)
cout << "Are you kidding me? @\\/@" <<endl;
else
printf("%s(%s%s%s)%s\n",organ[0][q[1]-1].c_str(),organ[1][q[2]-1].c_str(),organ[2][q[3]-1].c_str(),organ[1][q[4]-1].c_str(),organ[0][q[5]-1].c_str());
}
return 0;
}
cpp