Posted: Wed Sep 19, 2007 8:42 am
Code: Select all
Changed
Code: Select all
Changed
You missed this line, too.You must print a blank line between each test case.
Code: Select all
Changed
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++)
Code: Select all
Changed
Code: Select all
2
allwords
and
and
abc
Code: Select all
Case #1:
a
a
Case #2:
a
a
Code: Select all
Canged
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;
}
Thanks Jan.
Finally I got AC.
Your input helped me a lot.
You are a great helper.
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
Good Luck.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.
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;
}
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++;
}
}
}