求助!40分?

B2068 统计满足条件的 4 位数

ZZYTCCBS @ 2022-07-19 19:36:27

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    int t[105];
    for (int i=1; i<=n; i++)
    {
        cin>>t[i];
    } 
    int a, b, c, d, e;
    int z=0;
    for (int i=1; i<=n; i++)
    {
        a=t[i]%10;
        b=t[i]%100/10;
        c=t[i]%1000/10;
        d=t[i]/1000;
        e=a-b-c-d;
        if (e>0)
        {
            z++;
        }
    }
    cout<<z;
    return 0;
}

by Register_int @ 2022-07-19 19:38:58

@ZZYTCCBS 您这分离四位不对劲。要写成这样:

a=t[i]%10;
b=t[i]/10%10;
c=t[i]/100%10;
d=t[i]/1000;

by ZZYTCCBS @ 2022-07-19 20:18:22

@Register_int 十分感谢


by sieve @ 2023-02-15 13:10:55

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d,e,g,i,sum=0;
    cin>>a;
    for(i=1;i<=a;i++) {
        cin>>b;
        c=b%10;
        d=b/10%10;
        e=b/100%10;
        g=b/1000;
        if(c-d-e-g>0) sum=sum+1;
        else sum=sum;
    }
    cout<<sum;
    return 0;
}

by sieve @ 2023-02-15 13:11:34

这样就对了


by fkcufk @ 2023-03-26 09:09:14

@stanley12 sum=sum可以不写

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x,a,b,c,d,cnt=0;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> x;
        a = x / 1000 % 10;
        b = x / 100 % 10;
        c = x / 10 % 10;
        d = x / 1 % 10;
        if(d-a-b-c>0) cnt++;
    }
    cout << cnt;
    return 0;
}

|