892 - Finding words

All about problems in Volume 8. 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
cytmike
Learning poster
Posts: 95
Joined: Mon Apr 26, 2004 1:23 pm
Location: Hong Kong and United States
Contact:

892 - Finding words

Post by cytmike »

It seems that is an easy problem.
However, all submmisions are WA.
I wonder what happens there!!! :-?
Impossible is Nothing.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post 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
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

cytmike
Learning poster
Posts: 95
Joined: Mon Apr 26, 2004 1:23 pm
Location: Hong Kong and United States
Contact:

Post 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.

:x
but, still can't solve it ><
Impossible is Nothing.

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post 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

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post 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
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

The board doesn't show the first space in a line. My program outputs that space.

dpitts
New poster
Posts: 31
Joined: Tue Jun 17, 2003 10:10 pm

Post 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?

Carlos
System administrator
Posts: 1286
Joined: Sat Oct 13, 2001 2:00 am
Location: Valladolid, Spain
Contact:

Post 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.

sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post by sakhassan »

:roll:
Last edited by sakhassan on Fri May 19, 2006 1:29 pm, edited 1 time in total.

sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post 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:

IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

892 Find Words ...WA

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

IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

Post by IRA »

Who can help me?
Thanks in advance!

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

Post 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

x140l31
Learning poster
Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

Re: 892 - Finding words

Post 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');
	}

}

Post Reply

Return to “Volume 8 (800-899)”