483 - Word Scramble
Moderator: Board moderators
-
- New poster
- Posts: 1
- Joined: Wed Jan 16, 2008 7:57 pm
- Location: Dhaka,Bangladesh
- Contact:
wa 483
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;
}
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
Re: wa 483
Maybe you can do this way..rasel_0605003 wrote:how i can get several line input??
here is my code
Please suggest me
Code: Select all
while (gets(s)) {
// some process..
}
plz help me 483
cut after ac
Thanks buddy.
Thanks buddy.
Last edited by samin on Fri Apr 03, 2009 6:41 am, edited 1 time in total.
Re: plz help me 483
Hi, try this case(replace the asterisks with blank spaces):
My AC solution gives me:
Where your code gives:
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.
Code: Select all
*ABC**DEF***GHIJK****
Code: Select all
*CBA**FED***KJIHG****
Code: Select all
CBA*FED*KJIHG*
An array with size of 90000 would be sufficient.
Re: 483
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;
}
#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
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
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.
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.
-
- New poster
- Posts: 25
- Joined: Fri Apr 17, 2009 8:24 am
Re: 483
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;
}
-
- New poster
- Posts: 15
- Joined: Thu Sep 02, 2010 3:10 pm
- Location: Dhaka,Bangladesh
- Contact:
Re: 483 Word Scramble WA
Please check my code.I am getting WA.
thanks in advance...
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;
}
-
- New poster
- Posts: 15
- Joined: Thu Sep 02, 2010 3:10 pm
- Location: Dhaka,Bangladesh
- Contact:
Re: 483 Word Scramble PE!!!!!!!!!!!!!
Ok,ACCEPTED....
Re: 483 Word Scramble PE!!!!!!!!!!!!!
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.
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 483 Word Scramble PE!!!!!!!!!!!!!
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
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 483 Word Scramble PE!!!!!!!!!!!!!
i change this
with
and got WA...
Code: Select all
printf("%s ", s);
Code: Select all
printf("%s%c", str[i]);