我的PAT-BASIC代码仓:https://github.com/617076674/PAT-BASIC
原题链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805273883951104
题目描述:
知识点:哈希表
注意点:
(1)若用户选择的序号不存在,需要输出"Are you kidding me? @\/@"。这里面的"\"需要转义输出为"\\"。
(2)对于整行字符串,最好用getline读入,避免漏读换行符。
时间复杂度和空间复杂度均是O(n1 + n2 + n3),其中n1、n2、n3分别为输入第1、2、3行的字符串长度。
C++代码:
#include<iostream> #include<vector> #include<string> using namespace std; void generateArray(vector<string>& hands, string s); int main(){ string hand; string eye; string mouth; getline(cin, hand); getline(cin, eye); getline(cin, mouth); vector<string> hands; vector<string> eyes; vector<string> mouths; generateArray(hands, hand); generateArray(eyes, eye); generateArray(mouths, mouth); int count; cin >> count; int leftHand; int leftEye; int midMouth; int rightEye; int rightHand; for(int i = 0; i < count; i++){ cin >> leftHand >> leftEye >> midMouth >> rightEye >> rightHand; if(leftHand < 1 || leftHand > hands.size() || rightHand < 1 || rightHand > hands.size() || leftEye < 1 || leftEye > eyes.size() || rightEye < 1 || rightEye > eyes.size() || midMouth < 1 || midMouth > mouths.size()){ printf("Are you kidding me? @\\/@\n"); }else{ cout << hands[leftHand - 1] << "(" << eyes[leftEye - 1] << mouths[midMouth - 1] << eyes[rightEye - 1] << ")" << hands[rightHand - 1] << endl; } } } void generateArray(vector<string>& array, string s){ string tempString; for(int i = 0; i < s.length(); i++){ if(s[i] == '['){ tempString = ""; }else if(s[i] == ']'){ array.push_back(tempString); tempString = ""; }else{ tempString += s[i]; } } }C++解题报告: