Page 1 of 1
892 - Finding words
Posted: Mon Jul 12, 2004 5:03 pm
by cytmike
It seems that is an easy problem.
However, all submmisions are WA.
I wonder what happens there!!!

Posted: Tue Jul 13, 2004 8:37 am
by Dominik Michniewski
I've noticed this too ... I try also to solve this problem , but got WA of course

I see only two possibilities:
1. Exist one or more tricks, which are not discovered by noone.
2. Judge data has a mistake.
I have one question also: In description says about special treating hyphen if it very last character in line. What means this? If after hyphen exeists only spaces, it's very last character ? I don't think so
Best regards
DM
Posted: Tue Jul 13, 2004 10:42 am
by cytmike
The input description says:
Every line will be terminated by a character which isn't whitespace (which will be followed immediately by an end-of-line character).
So if this is true, there should not be whitespace after hyphen.
but, still can't solve it ><
Posted: Tue Jul 13, 2004 10:44 am
by Adrian Kuegel
I also got WA. I wrote a lot of asserts into my program, so I can say there exists no input where hyphen is the last non-space character in a line, but spaces follow. There exists also no input where hyphen is last character in a line, but there is no word with alphabet characters before it. And the next line following a hyphen always begins with non-space characters and has at least one alphabet character inside.
As there seems to be no tricky or invalid input, I fear that judge output has a mistake.
Here are the test cases that I used to check my program:
thi-s .i.s. a test-
#case. #
twenty-
one twenty-
two stop
#
this is a
testcase
twentyone
twentytwo
stop
Posted: Fri Jul 16, 2004 12:43 pm
by Dominik Michniewski
If I correct understand you, you test judges output very well

I am faced with the same problem like you - I think that my program should be correct , but I got WA as all others
Adrian, I think, that you lost one space is last line of your output. I think that this line should be "_stop" where "_" means space, but this should only cause PE ...
Best regards
DM
Posted: Fri Jul 16, 2004 3:12 pm
by Adrian Kuegel
The board doesn't show the first space in a line. My program outputs that space.
Posted: Fri Sep 24, 2004 2:29 am
by dpitts
This does seem like an easy problem. Could it be a problem with the judges data? Are we missing something in the problem description?
Although, the spec says that there is a space before the first word part, and after the second word part on the next line.
I really wonder if the judges output data is wrong. Any ideas?
Posted: Wed Nov 10, 2004 1:35 pm
by Carlos
Our fault, there was a point in judge's output
Anyway, I'm not too sure about PE on the output file, I'll rejudge and use some of your solution to find the right answer.
Posted: Fri May 19, 2006 1:27 pm
by sakhassan
Posted: Fri May 19, 2006 1:28 pm
by sakhassan
I wanna to make a comment about this problem ... hope it will be help to others....
1. this is a very simple problem
2. though only problem is that what will u do when u encounter a
'-' (hypen) at the end of a line.....
3. the word containing hypen will go to the next line
and a space is included in the place of a hypen.
4. and do the same as stated in the problem.....
Hope this time u will solve the problem wink:
892 Find Words ...WA
Posted: Tue Jul 04, 2006 8:00 pm
by IRA
I always got WA in this problem.
I don't know what reason.
Does it have any special input data?
Code: Select all
#include <stdio.h>
#include <string.h>
void RunSpecRule(char a[],int t)
{
int i;
for( i=t;i>=0;i-- )
if( a[i]==' ' )
{
a[i]='\n';
return;
}
}
int isSpecRule(char a[],int len)
{
int i;
for(i=len-1;i>=0;i--)
if( a[i]==' ' )
;
else if( a[i]!='-' )
return 0;
else if( a[i]=='-' )
return i;
return 0;
}
int main()
{
char sen[2000];
int i,len,flag,temp;
flag=0;
while(gets(sen))
{
len=strlen(sen);
if( temp=isSpecRule(sen,len) )
{
flag=1;
RunSpecRule(sen,temp);
for(i=0;i<len;i++)
if( (sen[i]>='a' && sen[i]<='z') || (sen[i]>='A' && sen[i]<='Z') )
printf("%c",sen[i]);
else if( sen[i]==' ' )
printf("%c",sen[i]);
else if( sen[i]=='\n' )
printf(" %c",sen[i]);
}else{
for(i=0;i<len;i++)
if( (sen[i]>='a' && sen[i]<='z') || (sen[i]>='A' && sen[i]<='Z') )
printf("%c",sen[i]);
else if( flag && sen[i]==' ' )
{
printf("\n ");
flag=0;
}else if( sen[i]==' ' )
printf("%c",sen[i]);
printf("\n");
}
}
return 0;
}
Posted: Sun Jul 16, 2006 6:57 pm
by IRA
Who can help me?
Thanks in advance!
Posted: Thu Jul 20, 2006 5:18 pm
by asif_rahman0
hi IRA,
Did you see this:
Code: Select all
Every line will be terminated by a character which isn't whitespace (which will be followed immediately by an end-of-line character). The input will be terminated by a line consisting of a single `#'.
hope you got it!!!.
rabbi
Re: 892 - Finding words
Posted: Wed Jun 11, 2008 1:05 am
by x140l31
Hi, I was reading this post but I can't solve my WA problem T.T
Can anyone help me?
Code: Select all
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null && !line.equals("#"))
{
int max = line.length() - 1;
if (line.charAt(max) == '-')
{
while (line.charAt(max) != ' ') max--;
}
String aux = line.substring(0, max + 1);
printLine(aux);
if (line.charAt(line.length() - 1) == '-')
{
aux = line.substring(max + 1);
line = br.readLine();
max = 0;
while (line.charAt(max) != ' ') max++;
aux = aux + line.substring(0, max);
printLine(aux);
printLine(line.substring(max));
}
}
}
private static void printLine(String aux) {
for (int i = 0; i < aux.length(); i++)
{
char c = aux.charAt(i);
if (isalpha(c) || c == ' ') System.out.print(c);
}
System.out.print('\n');
}
private static boolean isalpha(char c) {
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}
}