Problem Statement
You are given a
6
6
6-digit positive integer
N
N
N.
Determine whether
N
N
N satisfies all of the following conditions.
- Among the digits of N N N, the digit 1 1 1 appears exactly once.
- Among the digits of N N N, the digit 2 2 2 appears exactly twice.
- Among the digits of N N N, the digit 3 3 3 appears exactly three times.
中文题意
问题陈述
您将得到一个
6
6
6 位正整数
N
N
N 。
判断
N
N
N 是否满足以下所有条件。
- 在 N N N 中,数字 1 1 1 只出现 1 1 1次。
- 在数字 N N N 中,数字 2 2 2 恰好出现 2 2 2次。
- 在数字 N N N 中,数字 3 3 3 恰好出现 3 3 3次。
Constraints
- N N N is an integer satisfying 100000 ≤ N ≤ 999999 100000 \le N \le 999999 100000≤N≤999999.
Input
The input is given from Standard Input in the following format:
N N N
Output
Print Yes
if
N
N
N satisfies all the conditions described in the problem statement, and No
otherwise, in one line.
Sample Input 1
123233
Sample Output 1
Yes
123233
123233
123233 satisfies the conditions in the problem statement, so print Yes
.
Sample Input 2
123234
Sample Output 2
No
123234
123234
123234 does not satisfy the conditions in the problem statement, so print No
.
Sample Input 3
323132
Sample Output 3
Yes
Sample Input 4
500000
Sample Output 4
No
解法
方法一:使用桶计数的思想将这个 6 6 6位数字每一位取出来,分别存到数组对应的下标中,然后进行判断即可。
int num[10];
void solved() {
/* your code */
int n;
cin >> n;
while(n) {
num[n % 10] ++;
n /= 10;
}
if(num[1] == 1 && num[2] == 2 && num[3] == 3) cout << "Yes";
else cout << "No";
}
方法二:把输入当作字符串,直接排序,判断排序后的字符串是否等于 122333 122333 122333即可。
void solved() {
/* your code */
string s;
cin >> s;
sort(s.begin(), s.end());
if(s == "122333") cout << "Yes";
else cout << "No";
}