40分,希望各位大佬给予帮助!(求求了)

B2078 含 k 个 3 的数

President_Zhao @ 2023-07-09 17:20:20

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

by I_never_left @ 2023-07-09 17:25:56

@ZZYjinitaimei m 不能这么输入啊,得

long long a;
cin >> a;
while(a) {
    if(a % 10 == 3) ++ total;
    a /= 10;
}


by President_Zhao @ 2023-07-09 17:43:39

@hehe625 谢谢大佬,关注了


by President_Zhao @ 2023-07-09 17:47:46

改过之后还不对,40,有大佬帮忙解答一下吗?


by ZY10115 @ 2023-07-11 21:37:41

#include<bits/stdc++.h>
using namespace std;

int main()
{
  long long z,x,d=0;
  cin>>z>>x;
  while(z)
  {
    if(z%10==3)
      d++;
    z=z/10;
  }
  if(d==x)
    cout<<"YES";
  else
    cout<<"NO";
  return 0;
}

by President_Zhao @ 2023-07-17 16:18:45

@ZY10115 谢谢,已关


|