Page 3 of 9
Re: 483 WA i have searched all samples,and all are right.
Posted: Sat May 28, 2005 11:47 am
by kakashi
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.
}
Posted: Tue May 31, 2005 4:58 am
by sunnycare
3x very much
Why WA 483???Plz HELP!
Posted: Thu Sep 01, 2005 7:52 pm
by sharmin_bd
Why this is getting WA??I cant find the bugs
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;
}
}
}
Posted: Fri Sep 02, 2005 2:24 pm
by Nazmul Quader Zinnuree
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!
483...Why WA?Plzzz Help
Posted: Wed Sep 21, 2005 5:54 am
by sharmin_bd
Though it is the easy one..but i'm getting WA..

Could anyone plz help me by giving some difficult test case.Plzz help..Thanks in advance
Posted: Wed Sep 21, 2005 3:58 pm
by Raiyan Kamal
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
483 Why TLE?
Posted: Tue Dec 13, 2005 7:18 am
by Wei-Ming Chen
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
Posted: Wed Dec 14, 2005 5:49 pm
by Jan
Just make a input file with the following input set...
Input:
Then match the output set.
Output:
But your code enters into an infinity loop. Try to take input with gets().
Hope it helps.
Posted: Fri Dec 16, 2005 6:48 am
by Wei-Ming Chen
But it can run in my computer!
strange......
Posted: Sat Dec 17, 2005 12:58 am
by Jan
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...
Posted: Sat Dec 17, 2005 10:21 am
by Wei-Ming Chen
I change it to gets
but when it print ctrl+Z
How can I know it and return 0 ?
Posted: Sat Dec 17, 2005 10:36 am
by mamun
gets() returns NULL (0) on EOF (ctrl+z). So it should be simply
Code: Select all
char a[1000];
while( gets(a) ){
..........
}
Posted: Sun Dec 18, 2005 10:58 am
by Wei-Ming Chen
Thx , I got Ac
483 Presentation Error
Posted: Sun Feb 19, 2006 5:14 pm
by athlon19831
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;
}
Umm..
Posted: Tue Feb 21, 2006 2:29 pm
by Psyco
I think you have to delete some words.
Are you think too?