11220 - Decoding the message.

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

Moderator: Board moderators

lnr
Experienced poster
Posts: 141
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Post by lnr » Wed Sep 19, 2007 8:42 am

Code: Select all

Changed
Last edited by lnr on Wed Sep 19, 2007 7:00 pm, edited 2 times in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Wed Sep 19, 2007 12:18 pm

In my gcc, your code doesn't even pass the samples. And read the description again
You must print a blank line between each test case.
You missed this line, too.

Hope these help.
Ami ekhono shopno dekhi...
HomePage

lnr
Experienced poster
Posts: 141
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Post by lnr » Wed Sep 19, 2007 7:00 pm

Code: Select all

Changed
Last edited by lnr on Thu Sep 20, 2007 6:05 am, edited 2 times in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Thu Sep 20, 2007 1:22 am

Your code prints only the 'caseno'. I have tried both gcc and ms vc. Add the following part...

Code: Select all

   cin>>test;
//   {
      cin.get(); // to eliminate the newline after test
      cin.get(); // for the blank line
      for(i=1;i<=test;i++)
And then check the second sample very caerfully. Your code fails. Hope it helps.
Ami ekhono shopno dekhi...
HomePage

lnr
Experienced poster
Posts: 141
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Post by lnr » Thu Sep 20, 2007 6:05 am

Code: Select all

Changed
Last edited by lnr on Thu Sep 20, 2007 3:13 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Thu Sep 20, 2007 8:18 am

Almost correct. But missing some conditions. Try the cases..

Input:

Code: Select all

2

   allwords   
and 

and
abc
Output:

Code: Select all

Case #1:
a
a

Case #2:
a
a
Hope these help.
Ami ekhono shopno dekhi...
HomePage

lnr
Experienced poster
Posts: 141
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Post by lnr » Thu Sep 20, 2007 3:45 pm

Code: Select all

Canged
Last edited by lnr on Thu May 22, 2008 2:38 pm, edited 2 times in total.

himanshu
New poster
Posts: 17
Joined: Mon May 15, 2006 12:24 pm
Location: Hyderabad, India
Contact:

WA

Post by himanshu » Tue Oct 30, 2007 7:41 pm

Please help me with this. I have tried samples posted in this thread. Judge gives me WA

Code: Select all

#include<iostream>
#include<string>
#include<sstream>
using namespace std;

int main()
{
	int T;		
	cin >> T;
	string s;
	getline(cin, s);	
	getline(cin, s);
	for(int i = 1; i <= T; i++)
	{	
		cout << "Case #" << i << ":" << endl;
		while(getline(cin, s))
		{

			if(s == "")	
			{
				cout << endl;
				break;
			}

			istringstream sin(s);			
			string w;
			for(int j = 0; sin >> w;)
				if(j < w.size())
					cout << w[j++];
			cout << endl;
		}
			
	}
	return 0;
}
Thank You,
HG

lnr
Experienced poster
Posts: 141
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 11220 - Decoding the message

Post by lnr » Tue Jul 29, 2008 1:56 pm

Thanks Jan.
Finally I got AC.
Your input helped me a lot.
You are a great helper.

lnr
Experienced poster
Posts: 141
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 11220 - Decoding the message

Post by lnr » Tue Jul 29, 2008 2:00 pm

himanshu wrote:
Please help me with this. I have tried samples posted in this thread. Judge gives me WA
#include<iostream>
#include<string>
#include<sstream>
using namespace std;

int main()
{
int T;
cin >> T;
string s;
getline(cin, s);
getline(cin, s);
for(int i = 1; i <= T; i++)
{
cout << "Case #" << i << ":" << endl;
while(getline(cin, s))
{

if(s == "")
{
cout << endl;
break;
}

istringstream sin(s);
string w;
for(int j = 0; sin >> w;)
if(j < w.size())
cout << w[j++];
cout << endl;
}

}
return 0;
}
Thank You,
HG
I got accepted using C language functions.
I ran your code and found nothing wrong.
Evrything seems ok to me.
May be you are printing an extra blank line after the last case.
Good Luck.

aeiou
New poster
Posts: 21
Joined: Wed May 07, 2008 11:32 am

Re: 11220 - Decoding the message

Post by aeiou » Thu Sep 04, 2008 6:17 pm

To Himanshu , c d comments n change ur code...

Code: Select all


 #include<iostream>
    #include<string>
    #include<sstream>
    using namespace std;

    int main()
    {
       int T;      
       cin >> T;
       getchar(); 
       string s;
       getline(cin, s);   
       for(int i = 1; i <= T; i++)
       {   
          cout << "Case #" << i << ":" << endl;
          while(getline(cin, s))
          {

             if(s == "")   
             {
                cout << endl;          //remove this line;
                break;
             }

             istringstream sin(s);         
             string w;
             for(int j = 0; sin >> w;)
             {
               if .... 
                cout << w[j++];
             }
             cout << endl;               //add this line
          }
          if ( i < T )                            //dont print a blank line after the last test case
           cout << endl; 
       }
       return 0;
    }

naffi
New poster
Posts: 23
Joined: Wed Mar 19, 2008 12:25 pm
Location: BUET, Bangladesh
Contact:

Re: 11220 - Decoding the message

Post by naffi » Sun Sep 07, 2008 6:40 pm

I am getting RTE continuously. Can you help me?

Code: Select all

import java.util.Scanner;
import java.util.StringTokenizer;
 
class Decode
{
	public static void main(String args[])
	{
		Scanner inp = new Scanner(System.in);
		String str;
		char [] ans = new char[1000]; 
		int tc,counter,c,u;
		str = inp.nextLine();
		tc = Integer.parseInt(str);
		inp.nextLine();
		u = 1;
		while(tc > 0)
		{
			c = 0;
			while(true)
			{
				str = inp.nextLine();
				if(str.equals(""))break;						
				StringTokenizer stk = new StringTokenizer(str," ");
				counter = 0;				
				while(stk.hasMoreTokens())
				{
					String st = stk.nextToken();
					if(st.length() < counter+1)continue;
					ans[c] = st.charAt(counter);
					counter++;
					c++;
				}
				ans[c] = '$';
				c++;				
			}
			int x;
			System.out.println("Case #" + u + ":");
			for(x = 0; x < c; x++)
			{
				if(ans[x] == '$')
				{
					System.out.println("");					
				}
				else System.out.print(ans[x]);
			}
			if(tc != 1)System.out.println("");
			tc--;
			u++;
		}
	}
}
Always At Your Help.

aeiou
New poster
Posts: 21
Joined: Wed May 07, 2008 11:32 am

Re: 11220 - Decoding the message

Post by aeiou » Mon Sep 08, 2008 1:53 pm

To naffi ,

I cant find anything in ur code tat leads to rte..
usually for Java progs,the judge returns rte for WAs also..jus try increasing the length of the 'char' array to 4K or more.

aeiou
New poster
Posts: 21
Joined: Wed May 07, 2008 11:32 am

Re: 11220 - Decoding the message

Post by aeiou » Mon Sep 08, 2008 1:54 pm

To naffi,
change the class name to "Main"...for java progs the class name should always be "Main" (in this judge)...

naffi
New poster
Posts: 23
Joined: Wed Mar 19, 2008 12:25 pm
Location: BUET, Bangladesh
Contact:

Re: 11220 - Decoding the message

Post by naffi » Mon Sep 08, 2008 4:11 pm

to Mr. Vowel

Thanks a lot, i changed class name, and got AC.

Thanks again. :D :P
Always At Your Help.

Post Reply

Return to “Volume 112 (11200-11299)”