272 - TEX Quotes

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 272 -WA-Plz help to debug it!!!

Post by Obaida » Wed May 28, 2008 1:01 pm

Read my description above.
try_try_try_try_&&&_try@try.com
This may be the address of success.

hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 272 -WA-Plz help to debug it!!!

Post by hahahaken » Wed May 28, 2008 1:03 pm

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?

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 272 -WA-Plz help to debug it!!!

Post by Obaida » Wed May 28, 2008 1:07 pm

I think my one is correct here jan bi helped me with test case. :wink:
Though if you read the problem description carefully you can find which one is right.
try_try_try_try_&&&_try@try.com
This may be the address of success.

dreadlord
New poster
Posts: 19
Joined: Sat Apr 19, 2008 11:19 pm

Re: 272 -WA-Plz help to debug it!!!

Post by dreadlord » Wed May 28, 2008 5:56 pm

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?

Code: Select all

cout << "<<" << s << ">>"; 
Let's see, hahahaken... :roll: 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. :)

dreadlord
New poster
Posts: 19
Joined: Sat Apr 19, 2008 11:19 pm

Re: 272 -WA-Plz help to debug it!!!

Post by dreadlord » Wed May 28, 2008 5:59 pm

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?

hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 272 -WA-Plz help to debug it!!!

Post by hahahaken » Thu May 29, 2008 6:52 am

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

Code: Select all

Removed after AC
Last edited by hahahaken on Thu May 29, 2008 7:41 am, edited 1 time in total.

hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 272 -WA-Plz help to debug it!!!

Post by hahahaken » Thu May 29, 2008 7:09 am

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?

Code: Select all

Removed after AC

hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 272 -WA-Plz help to debug it!!!

Post by hahahaken » Thu May 29, 2008 7:46 am

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,

Code: Select all

while(getline(cin,s,'\0'))
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()

dreadlord
New poster
Posts: 19
Joined: Sat Apr 19, 2008 11:19 pm

Re: 272 -WA-Plz help to debug it!!!

Post by dreadlord » Thu May 29, 2008 10:44 am

hahahaken wrote:At last, I got AC, totally 7 tries, THANKS for everyone who has helped me b4
[...]
*CHEERS!* :lol:

Now it's time to try a new problem :wink:

You're welcome,

--Dread

zobayer
Experienced poster
Posts: 110
Joined: Tue May 06, 2008 2:18 pm
Location: CSE-DU, Bangladesh
Contact:

Re: 272 -WA-Plz help to debug it!!!

Post by zobayer » Thu Jun 12, 2008 3:18 pm

You should use a "\n" after each output, hope that will be fine if u r submitting in ANSI C.
You should not always say what you know, but you should always know what you say.

mahmoud.helmy
New poster
Posts: 1
Joined: Thu Oct 30, 2008 11:45 am

Re: 272 -WA-Plz help to debug it!!!

Post by mahmoud.helmy » Thu Oct 30, 2008 1:49 pm

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;
}

L I M O N
Learning poster
Posts: 58
Joined: Wed Dec 31, 2003 8:43 am
Location: Dhaka, Bangladesh
Contact:

Re: 272 -WA-Plz help to debug it!!!

Post by L I M O N » Sat Nov 01, 2008 6:14 pm

visit http://www.youngprogrammer.com and correct your solution. best of luck.

porker2008
New poster
Posts: 21
Joined: Wed Oct 08, 2008 7:04 am

Re: 272 -WA-Plz help to debug it!!!

Post by porker2008 » Mon Nov 03, 2008 5:07 pm

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.

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 272 -WA-Plz help to debug it!!!

Post by sazzadcsedu » Tue Dec 16, 2008 9:34 pm

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;
 
 }
 
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

dreadlord
New poster
Posts: 19
Joined: Sat Apr 19, 2008 11:19 pm

Re: 272 -WA-Plz help to debug it!!!

Post by dreadlord » Tue Dec 16, 2008 11:43 pm

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

Post Reply

Return to “Volume 2 (200-299)”