#include<iostream>
#include <string.h>
using namespace std;
int main()
{
printf("input the amount:\n");
int t;
scanf("%d",&t);
if(t<=0||t>1e3){
return 0;
}
for(int j=0;j<t;j++){
int const N=75;
string a[N];
int n;
printf("input the length:\n");
scanf("%d",&n);
if(n%2==0){
return 0;
}
printf("input the elem:\n");
for(int i=0;i<n;i++){
scanf("%s",&a[i]);
}
printf("input a letter or number:\n");
string m;
cin>>m;
int flat=0;
for(int i=0;i<n;i++){
if(a[i]==m){
flat=1;
}
}
if(flat==1){
printf("Yes\n");
}else{
printf("No\n");
}
}
return 0;
}
建议先搞懂题目的问题是什么。
1.测试用例中并没有输入字符串长度。所以这部分可以删除。
printf("input the length:\n");
scanf("%d",&n);
if(n%2==0){
return 0;
}
2.字符串输入可以预定义足够长度的char[]数组进行。
3.题目输出TRUE FLASE的标准不是字符串中包含字符就为TRUE。而是字符串每次去掉相邻的两个字符,是否最终可以剩下目标字符。
比如输入abcde,对于'a''c''e'可以为TRUE,对于‘b’'d'就为false.
可以再想一下思路。下文链接也有代码可以参考。
https://blog.csdn.net/TherAndI/article/details/123445738?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164722340816780271581280%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164722340816780271581280&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-1-123445738.pc_search_result_control_group&utm_term=deletions+of+two&spm=1018.2226.3001.4187