### shyam1909's blog

By shyam1909, history, 5 weeks ago,

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 :)

• +5

 » 5 weeks ago, # |   0 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, # ^ |   0 Thanks for the suggestion! :)
 » 5 weeks ago, # |   +3 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, # ^ |   0 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 :)