You are not logged in. Please login at www.codechef.com to post your questions!

×

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 -: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=607&page=show_problem&problem=208

asked 24 Jul '13, 09:36

ankitsablok89's gravatar image

2★ankitsablok89
1223
accept rate: 0%


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 :) , http://ideone.com/ag2IJN

link

answered 24 Jul '13, 23:31

v_akshay's gravatar image

4★v_akshay
1.2k91625
accept rate: 13%

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

link

answered 29 Dec '15, 17:59

tarasha_k's gravatar image

3★tarasha_k
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×3,820
×643
×47
×25

question asked: 24 Jul '13, 09:36

question was seen: 6,796 times

last updated: 29 Dec '15, 17:59