NeekT's blog

By NeekT, history, 5 weeks ago, In English

Hello everybody.

If i try the input for test 7 (the number 4744000695826) on my machine i get the right output (YES) but when i submit the code, the test on the same output gives the wrong answer (NO).

Here's my submission for the problem in the title (GNU C11)

#include "stdio.h"

int main(){
  int i,c;
  long long int n;
  scanf("%lld",&n);
  
  for(c=0; n>0; n/=10){
    if((n%10 == 4)||(n%10==7))
      c++;
  }
  
  if((c==4)||(c==7))
    printf("YES");
  else
    printf("NO");
  return 0;
}

I tried to mess around with the % operator but if i use %ld i get the same exact outcome (the problem is solved correctly on my machine but the test run by the online judge gives a different answer), so i tried with %d and at the very least i got some consistency: both my machine and the online judge spit out a clear NO.

Could someone help me figure out what's wrong here?

Here's the link to my latest submission in case you want to check out the full test details https://codeforces.com/problemset/submission/110/105489826

Here's a screenshot for the test on my machine

 
 
 
 
  • Vote: I like it
  • +8
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Hi, in your submit said,long int n. But, you should use long long int n in C11.

And, I have a advice. You can "CUSTOM TEST" in above menu bar in problem window. It is useful about this kind of problem. You and try and error.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Reference

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Aren't C and C++ two different languages? I thought these details would apply only to C++.

    • »
      »
      »
      5 weeks ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      No, You can also use the C standard streams printf/scanf in C++ too. That's why I linked the reference to avoid confusion.

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Thanks! I'll keep that in mind.