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

rasel_0605003
New poster
Posts: 1
Joined: Wed Jan 16, 2008 7:57 pm
Location: Dhaka,Bangladesh
Contact:

wa 483

Post by rasel_0605003 » Fri Jan 18, 2008 7:02 pm

how i can get several line input??
here is my code
Please suggest me
#include<stdio.h>
#include<string.h>

int main(void)
{
int i, j , p;
char s[1000];
gets(s);

j = 0;
for(i=0; ; i++)
{
if( s == ' ' && j == 0 )
{
for( p=i-1; p >= j; p--)
{
printf("%c",s[p]);
}
j=i;
}
else if( s == ' ')
{
for(p=i; p>j; p--)
{
printf("%c",s[p]);
}
j=i;

}
else if(s=='\0')
{
for(p=i; p>j; p--)
{
printf("%c",s[p]);
}
break;
}
}
return 0;
}
RASEL

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: wa 483

Post by helloneo » Sat Jan 19, 2008 5:31 am

rasel_0605003 wrote:how i can get several line input??
here is my code
Please suggest me
Maybe you can do this way.. :-)

Code: Select all

while (gets(s)) {
    //  some process..
}

maruf
New poster
Posts: 17
Joined: Sat May 24, 2008 6:00 pm

Re: 483

Post by maruf » Fri Jun 13, 2008 3:48 pm

removed after AC :D
lives for eternity......

samin
New poster
Posts: 6
Joined: Fri Jul 18, 2008 9:29 pm

plz help me 483

Post by samin » Wed Nov 19, 2008 9:31 pm

cut after ac

Thanks buddy.
Last edited by samin on Fri Apr 03, 2009 6:41 am, edited 1 time in total.

gba356
New poster
Posts: 15
Joined: Sat Apr 28, 2007 10:12 am
Location: Taiwan

Re: plz help me 483

Post by gba356 » Sun Nov 23, 2008 3:31 am

Hi, try this case(replace the asterisks with blank spaces):

Code: Select all

*ABC**DEF***GHIJK****
My AC solution gives me:

Code: Select all

*CBA**FED***KJIHG****
Where your code gives:

Code: Select all

CBA*FED*KJIHG*
Also, you need a bigger buffer for the problem description didn't mention how long the input will be.

An array with size of 90000 would be sufficient.

tasnif
New poster
Posts: 3
Joined: Fri Apr 03, 2009 5:53 am

Re: 483

Post by tasnif » Fri Apr 03, 2009 6:16 am

here is my code i am getting a runtime error but cant fix whats thr problem.i have tested several inputs and every one of them gives the correct output.
#include<stdio.h>
#include<string.h>

int main(void)
{
char p[101], temp; int i,k=0;
int j;

while(gets(p)!=NULL)
{
i=0;
k=0;


while(p[k]!='\0')
{
if(p[k]==' '||k==(int)strlen(p)-1)
{
if(p[k]==' ')
{
j=k-1;
}
else
{
j=k;
}



while(i<=j)
{
temp=p;
p=p[j];
p[j]=temp;
i++;
j--;
}
i=k+1;
}

k++;
}
puts(p);
}


return 0;

}

samin
New poster
Posts: 6
Joined: Fri Jul 18, 2008 9:29 pm

Re: 483

Post by samin » Fri Apr 03, 2009 6:43 am

try to take a large string such as char p[90000]

wayne_911
New poster
Posts: 4
Joined: Thu Jun 25, 2009 10:02 am

Re: 483

Post by wayne_911 » Thu Jun 25, 2009 6:40 pm

What is the meaning of "The input file will consist of several lines of several words." actually? Does it mean that all 3 lines of input must be typed in before the output is displayed? From my program code, the output is displayed after each line of input is inserted...but this get me WA :-?

Code: Select all

#include <iostream>
using namespace std;
#define maxCharacter 90000

void descend(int,int,char *);

int main()
{
	char sentence[maxCharacter];
	int initial;
	int lastChar;
	int i;

	while(cin.getline(sentence,90000))
	{
		initial=0;
		lastChar=0;

	for(i=0; sentence[i]!='\0' ; i++)
	{
		
		initial=lastChar;

		if(sentence[i]!=' ')
			continue;

		lastChar=i-1;
		descend(initial,lastChar,sentence);
		lastChar=i+1;

	}

	if(sentence[i]=='\0')
	{
		lastChar=i-1;
		descend(initial,lastChar,sentence);
	}


	cout<<endl<<endl;
	}

		
	return 0;
}

void descend(int initial,int lastChar,char *sentence)
{
	char hold;

	for (int i=lastChar; i>=initial; i--)
		cout<<sentence[i];

	cout<<" ";
	

}

	



mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 483

Post by mf » Sat Jun 27, 2009 11:06 am

It doesn't matter when your programs prints output. Judge first runs your programs, waits until completes, and only then compares your output with the correct output file.

Space (' ', ascii code 32) isn't the only whitespace character. There are a few others: tab (\t) and a couple of other weird characters. Use isspace() to check for a whitespace character.

asif_khan_ak_07
New poster
Posts: 25
Joined: Fri Apr 17, 2009 8:24 am

Re: 483

Post by asif_khan_ak_07 » Sun Sep 20, 2009 1:31 pm

I am getting WA for the following code

Code: Select all

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

char in[10000000],rev[10000000];
int ns,len,n,x;

int main(){
//	freopen("483.txt","r",stdin);
	while(gets(in)){
	len=strlen(in);

	for(int i=0;i<len;i++){
		while(in[i]!=' ' && in[i]!='\0' ){
			rev[ns++]=in[i];
			i++;
		}
		
		for(int j=ns-1;j>=0;j--)
			printf("%c",rev[j]);
		
		if(i<len)
		printf("%c",in[i]);

		ns=0;

	}
	
	printf("\n");
	
	
	}
return 0;
}

ujjal.ruet
New poster
Posts: 15
Joined: Thu Sep 02, 2010 3:10 pm
Location: Dhaka,Bangladesh
Contact:

Re: 483 Word Scramble WA

Post by ujjal.ruet » Fri Sep 03, 2010 9:56 am

Please check my code.I am getting WA.

Code: Select all

#include<stdio.h>
#include<string.h>
int main(){
char s[500];

int i,j,n,p;
while(gets(s)){
n=strlen(s);
j=0;
i=0;
for(i=0;i<n;i++){
    if(s[i+1]=='\0')  {
        for(p=i;p>=j;p--)
             printf("%c",s[p]);
         printf("\n");
         break;
        }
   else if(s[i+1]==' ')
        {
   for(p=i;p>=j;p--)
             printf("%c",s[p]);
             printf(" ");
             j=i+2;
             i=i+2;}

else
continue;
}

}

return 0;
}
thanks in advance...

ujjal.ruet
New poster
Posts: 15
Joined: Thu Sep 02, 2010 3:10 pm
Location: Dhaka,Bangladesh
Contact:

Re: 483 Word Scramble PE!!!!!!!!!!!!!

Post by ujjal.ruet » Fri Sep 03, 2010 11:15 am

Ok,ACCEPTED....

fkrafi
New poster
Posts: 13
Joined: Wed Sep 15, 2010 1:36 pm

Re: 483 Word Scramble PE!!!!!!!!!!!!!

Post by fkrafi » Wed Sep 15, 2010 6:06 pm

Why PE ?? Can anyone plz refer me some critical i/o.

Code: Select all

Solved....
Last edited by fkrafi on Tue Mar 01, 2011 2:48 pm, edited 1 time in total.

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 483 Word Scramble PE!!!!!!!!!!!!!

Post by sazzadcsedu » Sat Sep 18, 2010 7:43 pm

You are printing an extra space here:

Code: Select all

 
        s[j] = '\0';
        reverse(s, s+j);
        printf("%s(space)", s);

        Here you printing extra space,replace space with another character,you will find the problem.

Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

fkrafi
New poster
Posts: 13
Joined: Wed Sep 15, 2010 1:36 pm

Re: 483 Word Scramble PE!!!!!!!!!!!!!

Post by fkrafi » Fri Oct 01, 2010 3:51 am

i change this

Code: Select all

printf("%s ", s);
with

Code: Select all

printf("%s%c", str[i]);
and got WA... :D

Post Reply

Return to “Volume 4 (400-499)”