学题解的做法还不了

B2078 含 k 个 3 的数

makeway @ 2024-08-25 11:13:48

#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a;
    int b=0,c;
    while(a=getchar()!=' '){
        cin>>a;
        if(a=='3')b++;}
    cin>>c;
    if(c==b)cout<<"YES";
    else cout<<"NO";
    return 0;
}

by Obijeb @ 2024-08-25 11:18:29

不懂就问

为什么 a=getchar() 之后还要 cin>>a


by hyl_____ @ 2024-08-25 11:21:56

#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a;
    int b=0,c;
    while((a=getchar())!=' '){
        if(a=='3')b++;}
    cin>>c;
    if(c==b)cout<<"YES";
    else cout<<"NO";
    return 0;
}

by hyl_____ @ 2024-08-25 11:22:46

a=getchar() 那里要加括号


by makeway @ 2024-08-25 11:28:36

@Obijeb 说明我字符串没学好吧,复习ing....


|