Time. is important

If I input a sentence in one time and I input the sentence using getchar one by one then will the time taken be same

Yes, Both are O(length of the input), so they are basically the same. Practically getchar method, may give a better performance by some fractions of a second but the difference wont cause a TLE verdict to become an AC one and vice versa.