I think this case error: size of a is 1 char only.oulongbin wrote:char *a;
a=new char;
483 - Word Scramble
Moderator: Board moderators
-
- New poster
- Posts: 17
- Joined: Thu Jul 15, 2004 10:55 am
- Location: Poland, Rzeszow University of Technology
Re: 483 WA
483 why WA help plz
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]
[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]
-
- Experienced poster
- Posts: 115
- Joined: Tue Apr 06, 2004 7:04 pm
- Location: Venezuela
Hi !! coolyaya this some I/O
input :
ouput :
Hope it help
Keep posting !!
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
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
Keep posting !!

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]
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]
-
- Experienced poster
- Posts: 106
- Joined: Thu Jan 29, 2004 12:07 pm
- Location: Bangladesh
- Contact:
483 strange error!!!
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.
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.
-
- New poster
- Posts: 45
- Joined: Fri Jan 16, 2004 7:02 pm
- Location: CSE::BUET
- Contact:
-
- New poster
- Posts: 33
- Joined: Tue Jun 29, 2004 1:38 pm
- Location: IITM,chennai,Tamil Nadu,India
- Contact:
Strangely, I am getting TLE for 483
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';
}
}
Karthe
-
- Experienced poster
- Posts: 120
- Joined: Sat Nov 01, 2003 6:16 am
- Location: Dhaka (EWU)
hi
please check why u have got AC with PE
i have changed ur code
MAP[/code]
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;
}
-
- New poster
- Posts: 33
- Joined: Tue Jun 29, 2004 1:38 pm
- Location: IITM,chennai,Tamil Nadu,India
- Contact:
483 accepted but PE !!!! PLZ HELP ME
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;
}
#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;
}
-
- Experienced poster
- Posts: 122
- Joined: Tue Apr 16, 2002 10:07 am
483 WA i have searched all samples,and all are right....
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:
Waiting your help!!![/code]
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]