Page 2 of 9

Re: 483 WA

Posted: Thu Jul 29, 2004 10:45 pm
by Piotrek Mazur
oulongbin wrote:char *a;
a=new char;
I think this case error: size of a is 1 char only.

Posted: Fri Jul 30, 2004 10:47 am
by A1
As i know every word is less then 100 char long
so take an array of char, read a word
and just print every char from (len-1 to 0)
no need to cheak any thing else.

It is a very easy problem :wink:

Posted: Fri Jul 30, 2004 12:05 pm
by oulongbin
Thanks.I have changed my code.Now got AC.
Thank you very much! :D

483 why WA help plz

Posted: Fri Oct 22, 2004 6:45 pm
by coolyaya
This is my code...I can't find the bug...please help!

[c]#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int length,s,i,j,k,p,q=0;
char a[1000];

int main()
{
while(gets(a))
{
if(q>=1)
printf("\n");
string(a);
q++;
}

return 0;
}

int string(char a[])
{
s=0;
k=0;
length=strlen(a);
for(i=0;i<length;i++)
if(a==32)
s++;

for(i=0;i<length;i++)
{
if(a!=32)
k++;

if(a==32)
{
for(j=i-1;j>=i-1-k;j--)
printf("%c",a[j]);
k=0;
s--;
}
if(s==0)
{
for(j=length-1;j>=i+1;j--)
printf("%c",a[j]);
break;
}
}
}[/c]

Posted: Sat Oct 23, 2004 5:04 pm
by Ghust_omega
Hi !! coolyaya this some I/O
input :

Code: Select all

I love you.											roma
You love me
We're a happy family.
jajaja ummm             adfdsad sdfdasfnfoqf        pnfoqifowen    nowiqorowe
This is the input. why WA NOOOOOOOOO!!!!!!
SIHT SI 			TUPNI	GRRRR		TWO
LOOL 													faf			sa
ouput :

Code: Select all

I evol .uoy											amor
uoY evol em
er'eW a yppah .ylimaf
ajajaj mmmu             dasdfda fqofnfsadfds        newofiqofnp    eworoqiwon
sihT si eht .tupni yhw AW !!!!!!OOOOOOOOON
THIS IS 			INPUT	RRRRG		OWT
LOOL 													faf			
Hope it help
Keep posting !! :D

Posted: Sat Oct 23, 2004 6:36 pm
by kuonet
I also get a WA but I don't know where the mistake happened.
Here is the code, Thanks!
[c]
#include<stdio.h>
#include<string.h>

int main()
{
int n,count,j,tmp,i,k,max;
char a[10000] ="";
int b[10000] ={0};
while(gets(a) != NULL)
{
n = strlen(a);
count = 0;
j=0;
tmp = 0;
for(i=0;i<=n-1;i++)
{
if(a==' '){count++;b[j++]=i;}
}
if(count==0)
{
if(n>2)
for(i=0;i<=n/2;i++)
{
tmp=a;
a=a[n-i-1];
a[n-i-1]=tmp;
}
else if(n==2)
{
tmp=a[1];
a[1]=a[0];
a[0]=tmp;
}
}
else if(count==1)
{
k=b[0]-1;
for(i=0;i<=(b[0]-1)/2;i++)
{
tmp=a;
a=a[k];
a[k]=tmp;
k--;
}
k=n-1;
for(i=b[0]+1;i<=(b[0]+n)/2;i++)
{
tmp=a;
a=a[k];
a[k]=tmp;
k--;
}
}
else if(count!=0&&count!=1)
{
for(i=0;b[i+1]!=0;i++)
{
k = b[i+1]-1;
for(j=b+1;j<=(b+b[i+1])/2;j++)
{
tmp=a[j];
a[j]=a[k];
a[k]=tmp;
k--;
}
}
k=b[0]-1;
if(k<0){}
else if(k>=0)
{
for(i=0;i<=(b[0]-1)/2;i++)
{
tmp=a;
a[i]=a[k];
a[k]=tmp;
k--;
}
}
for(i=0;i<=n-1;i++)
{
if(b[i]==0&&i!=0){max=i-1;break;}
}
k=n-1;
for(i=b[max]+1;i<=(n+b[max])/2;i++)
{
tmp=a[i];
a[i]=a[k];
a[k]=tmp;
k--;
}
}
for(i=0;i<=n-1;i++)
{
printf("%c",a[i]);
}
printf("\n");
memset(b,0,sizeof(b));
memset(a,0,sizeof(a));
}
return 0;
}
[/c]

Posted: Sun Oct 24, 2004 6:53 am
by Raiyan Kamal
Dear kuonet, I found some mistake. Here are some inputs and the correct outputs. Your program fails in these cases.

INPUT

..aa
..as
aa..
as..

OUTPUT ( should be )

aa..
sa..
..aa
..as

YOUR PROGRAM SAYS

a.a.
s.a.
.a.a
.s.a

483 strange error!!!

Posted: Thu Nov 18, 2004 9:11 pm
by p!ter
Hi!

My input:

I love you.
You love me.
We're a happy family.

My output:

.uoy evol I
.em evol uoY
.ylimaf yppah a er'eW

I dont know what is wrong!!

Here is my code:

#include<stdio.h>

int max=2000000;

int main()
{
char temp,t[max];
int i,j,p,q;

while(fgets(t, max, stdin))
{
for(i=0; i<max; i++)
{
if(t=='\n')break;
if(t!='\32')
{
j=i+1;
while(j<max)
{
if(t[j]=='\n')break;
if(t[j]!='\32')j++;
else break;
}
j=j-1;
q=j;
for(p=i; p<=q; p++)
{
temp=t[p];
t[p]=t[q];
t[q]=temp;
q--;
}
i=j;
}
}
for(i=0; i<max; i++)
{
if(t!='\0')
{
printf("%c",t);
}
else break;
}
}
return 0;
}

Please help me!!
Thx.

Posted: Mon Nov 29, 2004 3:52 pm
by Heartattack!
You're supposed keep the order of words correct:

I love you.=
I evol .uoy

See the sample io. Good luck.

Strangely, I am getting TLE for 483

Posted: Sat Feb 12, 2005 1:02 pm
by Karthekeyan
Here is the simplest code I think is possible for problem 483, and i get TLE for this code....is there any better algo than this?

Code: Select all

#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
main()
{
  char ch;
  while(ch=getchar())
    {
      vector<char> st;
      while(ch!='\n')
	{
	  if(ch!=' ')
	    {
	      st.push_back(ch);
	    }
	  else
	    {
	      for(int j=st.size()-1;j>=0;j--)
		{
		  cout<<st[j];
		}cout<<" ";
	      st.clear();
	    }
	  ch=getchar();
	}
      for(int j=st.size()-1;j>=0;j--)
	{
	  cout<<st[j];
	}
      cout<<'\n';
    }
}

Posted: Sun Feb 13, 2005 1:19 pm
by mohiul alam prince
hi
please check why u have got AC with PE
i have changed ur code

Code: Select all

#include<vector> 
#include<cstdio> 
#include <string.h>

using namespace std; 
main() 
{ 
  char ch; 
  while(ch=getchar()) 
  { 
	  if ( ch == EOF)break;
      vector<char> st; 
      while(ch!='\n') 
	  { 
			if(ch!=' ') 
			{ 
				st.push_back(ch); 
			} 
			else 
			{ 
				for(int j=st.size()-1;j>=0;j--) 
				{ 
					cout<<st[j]; 
				}
				cout<<" "; 
				st.clear(); 
			} 
			ch=getchar();
			if ( ch == EOF)break;
	  } 
      for(int j=st.size()-1;j>=0;j--) 
	  { 
		    cout<<st[j]; 
	  } 
      cout<<'\n'; 
    } 
	return 0;
} 
MAP[/code]

Posted: Thu Feb 17, 2005 7:15 am
by Karthekeyan
thanx for that....i will c the P.E....

483 accepted but PE !!!! PLZ HELP ME

Posted: Mon Mar 28, 2005 8:50 pm
by thinker
My 483 is accepted but i got PE . i dont understant why i got it please help me. my code is following.
#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;

string str1;
string str2=" ";
char s[20000];


int main()
{
//freopen("input.in","r",stdin);

while(gets(s)!=NULL)
{

str1=s;
string str=str1+str2;
int l=0,pos=str.find(" ");
int size=str.find_last_of(str);



for(int i=0;i<=size;i++)
{
if(str.at(i)==' ')
{

if(pos!=size)
{
for(int i=pos-1;i>=l;i--)
{
cout<<str;
}

cout<<" ";
l=pos+1;
pos=str.find(" ",pos+1);
}


else
{
for(int i=pos-1;i>=l;i--)
{
cout<<str;
}
}


}


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

Posted: Mon Mar 28, 2005 10:07 pm
by Zyaad Jaunnoo
A PE is good enough :wink:

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

Posted: Tue Apr 12, 2005 2:20 am
by sunnycare
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]