题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805273883951104

这题坑点在非法输入还有小于1的值

代码

  1. #include<cstdio>
  2. #include<vector>
  3. #include<string>
  4. #include<iostream>
  5. using namespace std;
  6. int main(){
  7. string temp_str;
  8. vector<string>hands, eyes, mouth;
  9. int temp[5];
  10. getline(cin, temp_str);
  11. for(int i = 0; i < temp_str.size();){
  12. if(temp_str[i] == '['){
  13. for(int j = i; j < temp_str.size(); j++){
  14. if(temp_str[j] == ']'){
  15. hands.push_back(temp_str.substr(i + 1, j - i -1));
  16. //cout<<temp_str.substr(i + 1, j - i -1);
  17. i = j + 1;
  18. break;
  19. }
  20. }
  21. }
  22. else i++;
  23. }
  24. getline(cin, temp_str);
  25. for(int i = 0; i < temp_str.size();){
  26. if(temp_str[i] == '['){
  27. for(int j = i; j < temp_str.size(); j++){
  28. if(temp_str[j] == ']'){
  29. eyes.push_back(temp_str.substr(i + 1, j - i -1));
  30. //cout<<temp_str.substr(i + 1, j - i -1);
  31. i = j + 1;
  32. break;
  33. }
  34. }
  35. }
  36. else i++;
  37. }
  38. getline(cin, temp_str);
  39. for(int i = 0; i < temp_str.size();){
  40. if(temp_str[i] == '['){
  41. for(int j = i; j < temp_str.size(); j++){
  42. if(temp_str[j] == ']'){
  43. mouth.push_back(temp_str.substr(i + 1, j - i -1));
  44. //cout<<temp_str.substr(i + 1, j - i -1);
  45. i = j + 1;
  46. break;
  47. }
  48. }
  49. }
  50. else i++;
  51. }
  52. int k;
  53. scanf("%d", &k);
  54. for(int i = 0; i < k; i++){
  55. for(int j = 0; j < 5; j++) scanf("%d", &temp[j]);
  56. if(temp[0] > hands.size() || temp[1] > eyes.size() || temp[2] > mouth.size()||temp[3] > eyes.size()||temp[4] > hands.size()|| temp[0] < 1|| temp[1] < 1 || temp[2] < 1 || temp[3] < 1|| temp[4] < 1){
  57. printf("Are you kidding me? @\\/@\n");
  58. continue;
  59. }
  60. cout<<hands[temp[0] - 1]<< "(" <<eyes[temp[1] - 1]<<mouth[temp[2] - 1]<<eyes[temp[3] - 1] << ")" << hands[temp[4] - 1]<<endl;
  61. }
  62. }