题号:
CF1703A YES or YES?
题意翻译
题目描述
给定一个字符串 ss ,它的长度为 33 ,由大写字母和小写字母组成。
要求判断这个字符串是否为
YES
(不分大小写)。例如
yES
、Yes
、yes
都是合法的。输入格式
第一行,一个正整数 tt ( 1 \le t \le 10^31≤t≤103 ) ,表示测试组数。
接下来 tt 行,每行一个字符串 ss ,详见题目描述。
输出格式:
tt 行,对于每一个字符串,如果符合要求,输出
YES
。否则输出NO
。输入输出样例
输入 #1复制
10 YES yES yes Yes YeS Noo orZ yEz Yas XES输出 #1复制
YES YES YES YES YES NO NO NO NO NO说明/提示
The first five test cases contain the strings "YES", "yES", "yes", "Yes", "YeS". All of these are equal to "YES", where each character is either uppercase or lowercase.
看到这儿,也许有人会用struct(结构体),但我想到了一种代码更短,更容易理解的方法
(还不是我不会写struct)
Code:
#include<bits/stdc++.h>
using namespace std;
int i,ans,n;
string s;
int main(){
//一个个读入并判断
cin>>n;
for(i=1;i<=n;i++){
cin>>s;//无空格
ans=0;
//依次判断
if(s[0]=='Y'||s[0]=='y')ans++;
if(s[1]=='E'||s[1]=='e')ans++;
if(s[2]=='S'||s[2]=='s')ans++;
if(ans==3){//如果合法:
cout<<"YES"<<endl;
}else if(ans!=3){//不然
cout<<"NO"<<endl;
}
}
return 0;
}
代码献上,AC去吧(可能测试时有点慢,耐心等一等)...