c++40分求调(可壶关)!!!!!!

B2068 统计满足条件的 4 位数

jinxuanyi @ 2024-08-28 18:19:36

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

看了一会儿觉得没问题,求调

可壶关

by jinxuanyi @ 2024-08-28 18:21:11

请@我大佬们


by xyx404 @ 2024-08-28 18:24:46

@jinxuanyi

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

by jinxuanyi @ 2024-08-28 18:26:51

@xyx404 OK,我改一下,蟹蟹大佬,已关求壶关


by jinxuanyi @ 2024-08-28 18:28:39

已AC蟹蟹


by ryan2 @ 2024-10-25 20:21:10

用数组么?你不觉得很占空间么?

Code

#include <bits/stdc++.h>
using namespace std;
int n, x, q, b, s, g, c;
int main(){
    cin >> n;
    while (n--){
        cin >> x;
        q = x / 1000;
        b = x % 1000 / 100;
        s = x % 100 / 10;
        g = x % 10;
        if (q + b + s < g) c++;
    }
    cout << c << "\n";
    return 0;
}

是个人就能看懂,呵呵

必须AC


|