Блог пользователя shyam1909

Автор shyam1909, история, 3 года назад, По-английски

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
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится 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’

»
3 года назад, # |
  Проголосовать: нравится +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