483 - Word Scramble

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

Moderator: Board moderators

kakashi
New poster
Posts: 5
Joined: Thu May 26, 2005 10:58 am

Re: 483 WA i have searched all samples,and all are right.

Post by kakashi » Sat May 28, 2005 11:47 am

sunnycare wrote:I have searched all sample inputs on board, and all are right...

Why judge still give me a WA instead of a AC :(

here is my code:

Code: Select all

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

string word;

char ch;

void reverseOut(string &s)
{
	long i=s.length()-1;
	while(i>=0)
	{
		cout<<s[i];
		i--;
	}
}
void main()
{
	
	while(cin.get(ch))
	{
		if(ch==' '||ch=='\n')
		{
			reverseOut(word);
			cout<<ch;
			word="";
		}
		else
		{
			word+=ch;
		}
	}
}

Waiting your help!!![/code]
your code can`t process last input.
if last input doesn`t have ' 'or '\n',
the output must be wrong.

Code: Select all

void main()
{
	
	while(cin.get(ch))
	{
		if(ch==' '||ch=='\n')
		{
			reverseOut(word);
			cout<<ch;
			word="";
		}
		else
		{
			word+=ch;
		}
	}
                reverseOUt(word);//<----I think that you loss this.
}

sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

Post by sunnycare » Tue May 31, 2005 4:58 am

3x very much

sharmin_bd
New poster
Posts: 4
Joined: Tue Aug 30, 2005 6:42 pm

Why WA 483???Plz HELP!

Post by sharmin_bd » Thu Sep 01, 2005 7:52 pm

Why this is getting WA??I cant find the bugs :cry:

Code: Select all

#include<stdio.h>
#include<string.h>

void reverse(char *s){
	int i,j,c;
	for(i = 0,j = strlen(s)-1;i<j;i++,j--){
		c = s[i];
		s[i] = s[j];
		s[j] = c;
	}
}

void main(){
	int c,i = 0,flag = 0;
	char arr[500];
	while((c = getchar())!=EOF){
		if(c == '\n'){
			if(flag == 0)
				printf("\n");
			else{
				arr[i] = '\0';
				reverse(arr);
				printf("%s\n",arr);
			}
			i = 0;
			continue;
		}
		flag = 1;
		if(c != ' ' && c!='\t'){
			arr[i] = (char)c;
			i++;
		}
		else{
			arr[i] = '\0';
			reverse(arr);
			printf("%s%c",arr,c);
			i = 0;
			flag = 0;
		}
	}
}

Nazmul Quader Zinnuree
New poster
Posts: 42
Joined: Sun Jul 31, 2005 2:07 am
Location: SUST. Bangladesh
Contact:

Post by Nazmul Quader Zinnuree » Fri Sep 02, 2005 2:24 pm

You have to process the last word....
You do it only when the last word is followed by a '\n' or ' '.....
but not for the word immediately followed by EOF..
Good luck!

sharmin_bd
New poster
Posts: 4
Joined: Tue Aug 30, 2005 6:42 pm

483...Why WA?Plzzz Help

Post by sharmin_bd » Wed Sep 21, 2005 5:54 am

Though it is the easy one..but i'm getting WA.. :cry: Could anyone plz help me by giving some difficult test case.Plzz help..Thanks in advance

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal » Wed Sep 21, 2005 3:58 pm

Here are some cases, hope it helps.

INPUT:

Code: Select all

every dot is a . but not all dots are .s
is it a good test case ?
aa.bb.aa.
a.....aaaa..a..a.a..a
''.'sd.f'df'.df.'f.'
...adf....fds....sdf
.,,;;,',[,;,

sdfklj ,s,df, /////sdfdf
123456 aasdf
     568  sdf a1b2c3 :)
i am r2d2.
OUTPUT:

Code: Select all

yreve tod si a . tub ton lla stod era s.
si ti a doog tset esac ?
.aa.bb.aa
a..a.a..a..aaaa.....a
'.f'.fd.'fd'f.ds'.''
fds....sdf....fda...
,;,[,',;;,,.

jlkfds ,fd,s, fdfds/////
654321 fdsaa
     865  fds 3c2b1a ):
i ma .2d2r

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

483 Why TLE?

Post by Wei-Ming Chen » Tue Dec 13, 2005 7:18 am

I didn't think it's a hard problem, but I got TLE!

Here is my code:

#include <stdio.h>
int main()
{


thanks... I got Ac
Last edited by Wei-Ming Chen on Sun Dec 18, 2005 11:54 am, edited 1 time in total.

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

Post by Jan » Wed Dec 14, 2005 5:49 pm

Just make a input file with the following input set...

Input:

Code: Select all

a a b c
a a b c
Then match the output set.

Output:

Code: Select all

a a b c
a a b c
But your code enters into an infinity loop. Try to take input with gets().

Hope it helps.
Ami ekhono shopno dekhi...
HomePage

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

Post by Wei-Ming Chen » Fri Dec 16, 2005 6:48 am

But it can run in my computer!

strange......

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

Post by Jan » Sat Dec 17, 2005 12:58 am

Actually when I used the inputs manually it returns the output but, when I made a file and ran the code using that input file it returns nothing but an infinity loop...
Ami ekhono shopno dekhi...
HomePage

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

Post by Wei-Ming Chen » Sat Dec 17, 2005 10:21 am

I change it to gets
but when it print ctrl+Z
How can I know it and return 0 ?

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Sat Dec 17, 2005 10:36 am

gets() returns NULL (0) on EOF (ctrl+z). So it should be simply

Code: Select all

char a[1000];
while( gets(a) ){
   ..........
}

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

Post by Wei-Ming Chen » Sun Dec 18, 2005 10:58 am

Thx , I got Ac

athlon19831
New poster
Posts: 20
Joined: Thu Jan 19, 2006 2:32 pm

483 Presentation Error

Post by athlon19831 » Sun Feb 19, 2006 5:14 pm

i don't know why i got Presentation Error
it's my code
#include <iostream>
using namespace std;
#include <cstring>
#include <cstdio>
int main(int argc, char* argv[])
{
char str[1000];
char copy[1000];
char s[1000][1000];
long i,j,l,m,k;
bool flag,flag2;
while(gets(str))
{
l=strlen(str);
j=0;
copy[l]='\0';
for(i=l-1;i>=0;i--)
{
copy[j++]=str;
}
//cout<<copy<<endl;
k=0;m=0;flag=false;
for(i=0;i<=j;i++)
{
if(copy!=' ')
{
flag=true;
}
if(copy!=' '&&flag==true)
{
s[k][m++]=copy;
}
else if(copy==' '&&flag==true)
{
s[k][m]='\0';
k++;
m=0;
flag=false;
}
}
if(str[0]==' ')
{
flag2=false;
}
else
{
flag2=true;
}
if(!flag2)
{
k--;
}
for(i=k;i>=0;i--)
{
if(i!=0)
{
cout<<s<<" ";
//getchar();
}
else
{
cout<<s;
}
}
cout<<endl;
}
return 0;
}

Psyco
New poster
Posts: 14
Joined: Sat Jan 21, 2006 12:39 pm
Contact:

Umm..

Post by Psyco » Tue Feb 21, 2006 2:29 pm

I think you have to delete some words.

Are you think too?

Post Reply

Return to “Volume 4 (400-499)”