shyam1909's blog

By shyam1909, history, 5 weeks ago, In English

I was solving this problem problem .I encountered a problem while inputting the string . In my first submission i used scanf("%s",arr) which resulted in WA. Then i changed the input method to cin >> arr , then the submission became AC. Submission using scanf -> scanf Submission using cin -> cin

Submission using scanf() worked fine in my pc, but not in codeforces.

Can someone help me why does scanf() doesn't work here? Thanks in advance :)

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

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

It is not about your problem but I want to point out something. Instead of writing, bunch of if,else you can use ASCII values of numbers. I mean you can subtract char number from char zero. Thanks to this, you will get intended value.

Example: count += s[i] — ‘0’

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

The reason your scanf() is not working is because you actually use ios_base::sync_with_stdio(false); cin.tie(NULL); in your code. It speeds up your cin/cout but disables the sync with scanf/printf so you cannot use both at the same time.

Your code gets AC without ios_base::sync_with_stdio(false); cin.tie(NULL);: 129651408

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

    Thanks a lot! . Now I can understand the issue. I should stop the ios_base::sync and start to use scanf,printf instead of cin,cout hereafter in my codes. Thankss :)