答案

B2068 统计满足条件的 4 位数

zbc0403 @ 2024-07-25 16:40:38

#include <bits/stdc++.h>
using namespace std;
int a[1007];
int main()
{
    int n,num = 0;
    cin >> n;
    for (int i = 1;i <= n;i++)
    {
        cin >> a[i];    
    } 
    for (int i = 1;i <= n;i++)
    {
        int ge = a[i] % 10;
        int shi = a[i] / 10 % 10;
        int bai = a[i] / 100 % 10;
        int qian = a[i] / 1000;
        if(ge - (shi + bai + qian) > 0)
        {
            num++;
        }
    }
    cout << num;
    return 0;
}

by JIANG13959204364 @ 2024-07-25 18:37:33

假的


by Shenyufan13 @ 2024-08-10 10:59:36

@JIANG13959204364 我试过了,是真的


by guangtougun @ 2024-08-20 19:30:56

@zbc0403 大佬帮忙看一下,那错了


by guangtougun @ 2024-08-20 19:31:45

@zbc0403 代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int b,c=0;
    cin>>b; 
    int a[b];
    for(int i=0;i<b;i++){
        cin>>a[i];
    }
    for(int i=0;i<b;i++){
        int ge = a[i] % 10,shi = a[i] / 10 % 10,bai = a[i] / 100 % 10,qian = a[i] / 1000;
        if(a[i]-(ge+shi+bai+qian)>0) c++;
    }
    cout<<c;
    return 0;
}

by langyichen @ 2024-09-27 10:38:36

@guangtougun

题目上写的是个位数减十位,百位,和千位数要大于零,不是这个数减它的数字和大于零,所以判断条件应该改为:

ge-shi-bai-qian>0

|