The problem is in your method for fast string input i.e., str_input, modify it for newline charater.
The newline character is the reason for such weird behavior.
str_input(s); is giving you runtime error because during reading the integer t, the new line (’
') is read and skipped. So in next str_input() method while (c!=32 && c!=10), the check for c != 10 is skipping the next (second ) string input.
If the input was
then the runtime error would not occur ( see the extra line between first and second string ), see it on ideone here.
See your same code ACcepted here with out using the " str_input " method and rest of the code remains the same.