Page 5 of 10
Re: 272 -WA-Plz help to debug it!!!
Posted: Wed May 28, 2008 1:01 pm
by Obaida
Read my description above.
Re: 272 -WA-Plz help to debug it!!!
Posted: Wed May 28, 2008 1:03 pm
by hahahaken
Actually the most important thing I don't understand is that there are 2 versions of AC
One claims that just replace all " with `` and ' ' and you can get AC,
but another saying is that spaces and newlines have to be considered too
Which one is correct?
Re: 272 -WA-Plz help to debug it!!!
Posted: Wed May 28, 2008 1:07 pm
by Obaida
I think my one is correct here jan bi helped me with test case.
Though if you read the problem description carefully you can find which one is right.
Re: 272 -WA-Plz help to debug it!!!
Posted: Wed May 28, 2008 5:56 pm
by dreadlord
hahahaken wrote:Where should the below code added and what's the purpose?
I know how to output the spaces but I still don't manage to output line by line, I can just output a single continuous line, what else should I add?
Let's see, hahahaken...

That line is not only unnecessary but it would also make your program to get WA. I suggested you to add that line at the beginning of your program main loop, just after the "while" line, just for debugging purposes
before you submit it and with the aim of removing it
before you're going to submit it, so that you will be able to see what's what you're getting each time you get a string from cin. Did you read entirely my previous post?
I'm sure you know how to output the spaces, but how do you know
when and
where you should do? If you only get tokens of non-blanks character subsequences, how do you know whether there exists one, or two, or more blanks between two consecutive tokens? Or whether there exists one or more end of line marks between them?
At this point I can only suggest you to read carefully the problem description, to make several tests with your program before submitting it (including the description example), and also to read more carefully my previous post.
My feeling is that you didn't completely understand this problem nor your own program actual behaviour. Most times, being too hurried in solving a problem makes you to waste a lot of time in fixing what you do wrongly. On the contrary, spending a little time in reading and correctly understanding the problem shall make you to save a lot of time.
In either case, good luck.

Re: 272 -WA-Plz help to debug it!!!
Posted: Wed May 28, 2008 5:59 pm
by dreadlord
hahahaken wrote: [...]
One claims that just replace all " with `` and ' ' and you can get AC,
[...]
Yes, just replace that, but also remember to
leave unchanged the rest of characters. Are you sure you do so? Do you believe that your program copies to the output all input characters others than ",
including blanks and end of line marks?
Re: 272 -WA-Plz help to debug it!!!
Posted: Thu May 29, 2008 6:52 am
by hahahaken
Finally, I can produce the correct input with a text file, but I don't know how to move back to the console, pls give me a help
Re: 272 -WA-Plz help to debug it!!!
Posted: Thu May 29, 2008 7:09 am
by hahahaken
I've tried to move the code used on file back to console mode, but wrong answer still occurs, why?
I know how to use the "<<" and ">>", they are used to tell me where does the output start and where it ends. Is my WA related to "|" or anything else?
Re: 272 -WA-Plz help to debug it!!!
Posted: Thu May 29, 2008 7:46 am
by hahahaken
At last, I got AC, totally 7 tries, THANKS for everyone who has helped me b4
SPECIALLY THANKS for the AC of "dreadlord", it helps me to find out what's the differences between a AC and mine and debug
I discovered that the trick is using,
then the program will keep input sth until "\0" end of file is reached, including spaces and newlines
I try to press Ctrl+Z after the end of input and press again, or just press enter after the end of input and Ctrl+Z, I have discovered that there will not be a newline after the output for the 1st method while the 2nd one has
P.S. To solve this problem, I think one should clearly know the differences of the following commands:
1. cin
2. cin.get()
3. cin.getline()
4. getline()
5. gets()
6. getchar()
Re: 272 -WA-Plz help to debug it!!!
Posted: Thu May 29, 2008 10:44 am
by dreadlord
hahahaken wrote:At last, I got AC, totally 7 tries, THANKS for everyone who has helped me b4
[...]
*CHEERS!*
Now it's time to try a new problem
You're welcome,
--Dread
Re: 272 -WA-Plz help to debug it!!!
Posted: Thu Jun 12, 2008 3:18 pm
by zobayer
You should use a "\n" after each output, hope that will be fine if u r submitting in ANSI C.
Re: 272 -WA-Plz help to debug it!!!
Posted: Thu Oct 30, 2008 1:49 pm
by mahmoud.helmy
Hi, this code gets wrong answer.
Hope to help
thx
Code: Select all
#include <iostream>
#include<fstream.h>
#include<string>
using namespace std;
char str[5000];
//char temp[1000];
string temp="";
void fn(string str)
{
int Counter=0;
for(int i=0;i<str.size();i++)
{
if(str[i]=='"')
{
Counter++;
if(Counter%2!=0) // 1 3 5 7 9 and so on.
{
temp+="``";
}
else
temp+="''";
}
else
{
temp+=str[i];
}
}
}
int main()
{
string s;
string paragraph;
do {
getline(cin, s);
paragraph += s + "\n";
} while (s.length() > 0);
fn(paragraph);
cout<<temp;
return 0;
}
Re: 272 -WA-Plz help to debug it!!!
Posted: Sat Nov 01, 2008 6:14 pm
by L I M O N
visit
http://www.youngprogrammer.com and correct your solution. best of luck.
Re: 272 -WA-Plz help to debug it!!!
Posted: Mon Nov 03, 2008 5:07 pm
by porker2008
To "mahmoud.helmy"
Actually, you need not to memorize what the input is.
You just need to make an integer to memorize what the quato is.
For example, you can use this code to finish the job.
Code: Select all
char c;
int num=0;
while((c=getchar())!=EOF){
if(c=='"'&&num==0) {num=1; printf("``");}
else if(c=='"'&&num==1) {num=0; printf("''");}
else putchar(c);
}
Best Regards.
Re: 272 -WA-Plz help to debug it!!!
Posted: Tue Dec 16, 2008 9:34 pm
by sazzadcsedu
whats wrong with my code!!!!!
i got wrong ans!!
Code: Select all
#include<stdio.h>
int main()
{
char ch;
int count=1;
while((ch=getchar())!=EOF)
{
if(ch=='"'){
if(count%2)
{
printf("~~");
count=0;
}
else
{
printf("''");
count=1;
}
}
else
printf("%c",ch);
}
return 0;
}
Re: 272 -WA-Plz help to debug it!!!
Posted: Tue Dec 16, 2008 11:43 pm
by dreadlord
sazzadcsedu wrote:whats wrong with my code!!!!!
i got wrong ans!!
Code: Select all
[...]
if(count%2)
{
printf("~~");
count=0;
}
[...]
I find the printf line rather worrisome. What are exactly those characters you're printing? I see a couple of tildes, not ``
--Dread