NeekT's blog

By NeekT, history, 5 months 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 months 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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you very much.

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

    Hi there, I have the same problem as NeekT, and I tried using your solution. However, for some reason my test case 7 is still giving wa. I am already using long long int and I am using c.

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

      You used this:

      long int a;

      You should use:

      long long int a;

      In Addition, when you are scanning "a" you should use :

      scanf("%lld",&a);

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

        Oh yea sorry, that was what I submitted. However, in my own IDE, I changed it to long long int a already and tried inputting test case 7, and I still got wa. I also submitted the code to codeforces and still got wa in test case 7.

        Here is my submission https://codeforces.com/contest/110/submission/115371703

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

          In your pow_num function is using integers when you are using long long int in your program I advice you to use entire variables as long long int.

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

            No you can't, pow uses doubles which has precision issues.

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

            Wow. I would never have thought of that haha. Thanks for the help. Sorry Im a complete beginner lol.

»
5 months 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 months 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 months 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 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Thanks! I'll keep that in mind.