Page 6 of 9

wa 483

Posted: Fri Jan 18, 2008 7:02 pm
by rasel_0605003
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;
}

Re: wa 483

Posted: Sat Jan 19, 2008 5:31 am
by helloneo
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..
}

Re: 483

Posted: Fri Jun 13, 2008 3:48 pm
by maruf
removed after AC :D

plz help me 483

Posted: Wed Nov 19, 2008 9:31 pm
by samin
cut after ac

Thanks buddy.

Re: plz help me 483

Posted: Sun Nov 23, 2008 3:31 am
by gba356
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.

Re: 483

Posted: Fri Apr 03, 2009 6:16 am
by tasnif
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;

}

Re: 483

Posted: Fri Apr 03, 2009 6:43 am
by samin
try to take a large string such as char p[90000]

Re: 483

Posted: Thu Jun 25, 2009 6:40 pm
by wayne_911
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<<" ";
	

}

	



Re: 483

Posted: Sat Jun 27, 2009 11:06 am
by mf
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.

Re: 483

Posted: Sun Sep 20, 2009 1:31 pm
by asif_khan_ak_07
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;
}

Re: 483 Word Scramble WA

Posted: Fri Sep 03, 2010 9:56 am
by ujjal.ruet
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...

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

Posted: Fri Sep 03, 2010 11:15 am
by ujjal.ruet
Ok,ACCEPTED....

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

Posted: Wed Sep 15, 2010 6:06 pm
by fkrafi
Why PE ?? Can anyone plz refer me some critical i/o.

Code: Select all

Solved....

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

Posted: Sat Sep 18, 2010 7:43 pm
by sazzadcsedu
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.


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

Posted: Fri Oct 01, 2010 3:51 am
by fkrafi
i change this

Code: Select all

printf("%s ", s);
with

Code: Select all

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