40分求调

B2078 含 k 个 3 的数

__F__ @ 2024-07-16 14:52:06

40分代码

#include<bits/stdc++.h> 
using namespace std;
int main(){
    int m,k,s=0;
    cin>>m>>k;
    int t=m;
    while(t!=0){
        if(t%10==3){
            s++;
        }
        t=t/10;
    }
    if(s==k&&m%19==0)
     {
        cout<<"YES"; 
     }else{
        cout<<"NO";
     }
     return 0;
}

by fire_flies @ 2024-07-16 14:55:47

@yuhan09 我来


by YCN_AK_NOI @ 2024-07-16 14:56:01

@yuhan09 开long long


by YCN_AK_NOI @ 2024-07-16 14:56:55

把int改成long long


by Bitwise_Operation @ 2024-07-16 14:57:17

@yuhan09 这个m\le 10^{15},不能用int存,其他的也存不下,应该用string存,然后遍历每一位统计'3'的个数,最后判断


by UncleSam_Died @ 2024-07-16 14:57:26

@yuhan09 不开 long long 见祖宗:)

#include<bits/stdc++.h> 
using namespace std;
#define int long long
signed main(){
    int m,k,s=0;
    cin>>m>>k;
    int t=m;
    while(t!=0){
        if(t%10==3){
            s++;
        }
        t=t/10;
    }
    if(s==k)
     {
        cout<<"YES"; 
     }else{
        cout<<"NO";
     }
     return 0;
}

by fire_flies @ 2024-07-16 14:58:09

@yuhan09 ```

#include<bits/stdc++.h>
using namespace std;
int m,k,l;
int main(){
    cin>>m>>k;
    while(m){
        if(m%10==3){
            l++;
        }
        m/=10;
    }
    if(l==k){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
}

by rain_wu @ 2024-07-16 14:58:41

要不,试试字符挨个getchar?(也可以开longlong)


by YCN_AK_NOI @ 2024-07-16 14:59:22

#include<bits/stdc++.h>
using namespace std;
long long m, k, s,t;
int main() {
    cin >> m >> k;
    t = m;
    while (t > 1) {//是大于1,因为除不到0
        if (t % 10 == 3) {
            s++;
        }
        t = t / 10;
    }
    if (s == k) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}

by YCN_AK_NOI @ 2024-07-16 14:59:58

@Bitwise_Operation 可能人家字符串都没学


by YCN_AK_NOI @ 2024-07-16 15:00:38

@Bitwise_Operation 不过确实是个好方法


| 下一页