It is showing wrong answer
#include
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int count=0;
int n;
cin>>n;
while(n){
int last=n%10;
if(last!=4&&last!=7){
count++;
}
n=n/10;
}
cout<<count<<"\n";
}
return 0;
}
The answer is simply the number of unlucky digits. Your logic seems to be wrong.
AC code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
string s;
cin >> s;
int ans = 0;
for (char i : s) if (i != '4' && i != '7') ++ans;
cout << ans << '\n';
}
}
Also, notice that n can be as large as 10^{100000} which won’t even fit in long long
. That’s why you should use a string.
1 Like
my logic is right…
as you told…
n value is large…
that’s why we should use string…
thanks bhaiya…