【AtCoder】Beginner Contest 380-A.123233

题目链接

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 100000N999999.

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";
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值