Problem Statement
Let us call a string consisting of uppercase and lowercase English alphabets a wonderful string if all of the following conditions are satisfied:
- The string contains an uppercase English alphabet.
- The string contains a lowercase English alphabet.
- All characters in the string are pairwise distinct.
For example, AtCoder
and Aa
are wonderful strings, while atcoder
and Perfect
are not.
Given a string SS, determine if SS is a wonderful string.
Constraints
- 1≤∣S∣≤1001≤∣S∣≤100
- SS is a string consisting of uppercase and lowercase English alphabets.
Input
Input is given from Standard Input in the following format:
SS
Output
If SS is a wonderful string, print Yes
; otherwise, print No
.
Sample 1
Inputcopy | Outputcopy |
---|---|
AtCoder | Yes |
AtCoder
is a wonderful string because it contains an uppercase English alphabet, a lowercase English alphabet, and all characters in the string are pairwise distinct.
Sample 2
Inputcopy | Outputcopy |
---|---|
Aa | Yes |
Note that A
and a
are different characters. This string is a wonderful string.
Sample 3
Inputcopy | Outputcopy |
---|---|
atcoder | No |
It is not a wonderful string because it does not contain an uppercase English alphabet.
Sample 4
Inputcopy | Outputcopy |
---|---|
Perfect | No |
It is not a wonderful string because the 22-nd and the 55-th characters are the same.
//字符串中必须包含一个大写英文字母。
//字符串中必须包含一个小写英文字母。
//字符串中的所有字符都是互不相同的。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
cin >> s;
int num[257] = { 0 };//定义一个数组用来记录每个字母出现的次数
/*数组大小为257是因为ASCII码中字符的范围是0-255,加上一个额外的位置用于处理可能的负数索引(虽然在这个代码中不会用到)*/
bool ok = 1;
bool u = 0, l = 0;
for (char c : s) {//这个很有用,望灵活掌握:定义一个字符串,逐个遍历字符串s
if ('a' <= c && 'z' >= c)l = 1;//判断是否有小写字母
if ('A' <= c && 'Z' >= c)u = 1;//判断是否有大写字母
num[c]++;//字母每出现一次就在字母对应的位置+1
if (num[c] >= 2)ok = 0;
}
if (ok && l && u)cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}