qwq!!!

B2078 含 k 个 3 的数

shb20111113 @ 2023-07-27 22:50:21

这是题解代码:

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    long long m;
    int k,cnt3 = 0;
    cin>>m>>k;
    while(m){
        if(m % 10 == 3)++cnt3;
        m /= 10;
    } 
    if(cnt3 == k)cout << "YES";
    else cout << "NO"; 
    return 0;
}

这是我的代码:

#include <bits/stdc++.h>
using namespace std;
long long sum=0;
int cf(int x){
    while(x){
        if(x%10==3)sum++;
        x/=10;
    }
}
int main()
{
    long long n,k;
    cin>>n>>k; 
    cf(n);
    //cout<<sum<<endl;
    if(sum==k)cout<<"YES";
    else cout<<"NO"; 
    return 0;
}

有什么区别吗???


by HashHacker_Peas @ 2023-07-27 23:06:18

@shb20111113 cf函数都没有返回值,应该用void


by HashHacker_Peas @ 2023-07-27 23:08:34

@shb20111113 还有cf函数的形参的类型应该是longlong


by shb20111113 @ 2023-07-28 19:39:53

@xxx666xxx 谢谢Thanks♪(・ω・)ノ!磁铁结


|