70求调

B2078 含 k 个 3 的数

KokCair @ 2024-08-29 22:03:16


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

by wky_wsy @ 2024-08-29 22:07:46

有一种神奇的东西叫字符串


by wky_wsy @ 2024-08-29 22:12:16

@114514xiaohai
帮你改了一下,通过记录

#include <bits/stdc++.h>
using namespace std;
int main () {
    string m;//用字符串存数据,省时省力 
    int k,g=0;
    cin>>m;
    int l=m.size(); 
    /*for(m=m;m>=10;m/=10) {
        if(m%10==3) {
            g++;
        }
    }*/
    for(int i=0;i<l;i++){
        if(m[i]=='3'){
            g++;
        }
    }
    cin>>k;
    if(g==k) {
        cout<<"YES";
    }
    if(g!=k) {
        cout<<"NO";
    }
    return 0;
}

by KokCair @ 2024-08-29 22:15:19

@wky_wsy 谢了,不过已经用数字过了


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

by chenzhishuo2012 @ 2024-09-04 13:49:22

@114514xiaohai 求互关

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

|