C - Perfect String

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

InputcopyOutputcopy
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

InputcopyOutputcopy
Aa
Yes

Note that A and a are different characters. This string is a wonderful string.

Sample 3

InputcopyOutputcopy
atcoder
No

It is not a wonderful string because it does not contain an uppercase English alphabet.

Sample 4

InputcopyOutputcopy
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;
}

  • 23
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值