CF1644A Doors and Keys 题解

  1. 1. 题意简化
  2. 2. Solution

题意简化

六个字母,任意一字母大写若出现在小写的前面,输出 NO,否则输出 YES

Solution

字典暴力模拟,这样能够减少代码量。使用 toupper() 使代码更整洁。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<bits/stdc++.h>
using namespace std;
bool flag[130];

int main()
{
int T;
cin>>T;
while(T--)
{
memset(flag,0,sizeof(flag));
string str;
int t=0;
cin>>str;
for(int i=0;i<str.length();i++)
if(isupper(str[i]))
{
if(!flag[str[i]]) {cout<<"NO\n";t=1;break;}
}
else flag[toupper(str[i])]=true;
if(t==0) cout<<"YES\n";
}
return 0;
}