Uva 272 - Tex Quotes

I wrote the code for the following problem but I keep on getting wrong answers its such a simple problem, but don’t know where am I going wrong in my code, here is my code for reference

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>

using namespace std;

int main(){


        string inputString;

        while( getline( cin , inputString ) ){


                int nDoubleQuotes = 0;

                for(int i = 0 ; i < (int)inputString.length() ; ++i){

                    if( inputString[ i ] == '"' ){
                        ++nDoubleQuotes;

                        nDoubleQuotes = nDoubleQuotes%2;

                        if( nDoubleQuotes == 1 )
                            cout << "``";
                        else
                            cout << "''";
                    }

                    else
                        cout << inputString[ i ];
                }

                cout << '\n';

        }

        return 0;
}

kindly help me identify the anomaly in the code. here is the link to the problem -: Online Judge

I think you should process and print each line one by one instead of printing character by character, I tried processing the whole string at once and then printing the entire paragraph but it showed WA, then I tried processing and printing 1 line at a time and it got AC, here’s a link to my ACed code, hope it helps :slight_smile: , ag2IJN - Online C++ Compiler & Debugging Tool - Ideone.com

Could you explain why character by character reading gave WA? I had the same problem but I cant find a reason to it.

When you are taking a line input and traversing through the string and printing the modified string you are actually ignoring the new line.

Eg:- Sample i/o- He said, “I am doing good,
hope you are also.”

Sample o/p:- He said, ``I am doing good,
hope you are also.’’

Your code will o/p:- ``I am doing good,hope you are also.’’

o/p=output
i/p=input

can’t you see the date its four years ago Lmao