B组刷题汇总~
1.测试点解决
0号测试点为题目给出的测试用例,1号测试点数组中含有 0 值,需进行特判,2号测试点中含有负数值,需要进行特判!
2.注意点
题目所给输出无法正常全部输出,需要额外添加转义符号。
3.代码(C++)
使用了stl 容器中的 string。
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
const int maxn = 11;
int main(){
string hands[maxn],eyes[maxn],mouths[maxn];
string hand,eye,mouth;
int handnum = 0,eyenum = 0,mouthnum = 0;
getline(cin,hand);
for(int i = 0;i < hand.size();i++){
if(hand[i] == '['){
i++;
while(hand[i] != ']'){
if(hand[i] != ' '){
hands[handnum] += hand[i];
}
i++;
}
handnum++;
}
}
getline(cin,eye);
for(int i = 0;i < eye.size();i++){
if(eye[i] == '['){
i++;
while(eye[i] != ']'){
if(eye[i] != ' '){
eyes[eyenum] += eye[i];
}
i++;
}
eyenum++;
}
}
getline(cin,mouth);
for(int i = 0;i < mouth.size();i++){
if(mouth[i] == '['){
i++;
while(mouth[i] != ']'){
if(mouth[i] != ' '){
mouths[mouthnum] += mouth[i];
}
i++;
}
mouthnum++;
}
}
int n;
scanf("%d",&n);
int sea[n][6];
for(int i = 0;i < n;i++){
for(int j = 0;j < 5;j++){
scanf("%d",&sea[i][j]);
}
}
for(int i = 0;i < n;i++){
//以下为判别语句。
if(sea[i][0] > handnum || sea[i][1] > eyenum || sea[i][2] > mouthnum || sea[i][3] > eyenum || sea[i][4] > handnum || sea[i][0] <= 0 || sea[i][1] <= 0 || sea[i][2] <= 0 || sea[i][3] <= 0 || sea[i][4] <= 0){
printf("Are you kidding me? @\\/@\n"); //额外添加转义符!!!
}else{
cout << hands[sea[i][0] - 1] << "("<< eyes[sea[i][1] - 1] << mouths[sea[i][2] - 1] << eyes[sea[i][3] - 1] <<")"<< hands[sea[i][4] - 1] << '\n';
}
}
return 0;
}