Page 11 of 15
492 WA help plz
Posted: Mon Dec 08, 2008 1:08 pm
by LMY
Here is my code.
I try some input by the wa discuss topic before but still get wa
can someone help me plz !!
Code: Select all
#include <iostream>
using namespace std;
#define MAX 1000000
int main(){
char s[MAX];
char c;
bool begin;
bool vowel;
bool consonant;
//freopen("in", "r", stdin);
while (cin.getline(s, MAX)){
begin = true;
//vowel = true;
for (int i=0; ;i++){
// alphabet
if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <='z')){
if (begin){
if (!(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u' || s[i]=='A' || s[i]=='E' || s[i]=='I' || s[i]=='O' || s[i]== 'U')){
c = s[i];
consonant = true;
vowel = false;
}
else{
cout << s[i];
consonant = false;
vowel = true;
}
begin = false;
}
else
cout << s[i];
}
else {
if (consonant) {
cout << c << "ay";
consonant = false;
vowel = false;
}
else if (vowel){
cout << "ay";
consonant = false;
vowel = false;
}
if (s[i]!='\0')
cout << s[i];
else
break;
begin = true;
}
}
cout << endl;
}
return 0;
}
Here is my input
Code: Select all
alex
Alex
This is the input.
He is a boy.
Object123oriented,..,.Programming
000000000
aaaaaaaaaaaa
Aaaaaaaaaaaa
computerprogrammingII
cse-1204 Computer programming II
ACM programming contest was held on 10th November, 2001 at BUET.
an a eye An A Eye Bee BEE Dhaka-1205 1st last.
and output
Code: Select all
alexay
Alexay
hisTay isay hetay inputay.
eHay isay aay oybay.
Objectay123orienteday,..,.rogrammingPay
000000000
aaaaaaaaaaaaay
Aaaaaaaaaaaaay
omputerprogrammingIIcay
secay-1204 omputerCay rogrammingpay IIay
ACMay rogrammingpay ontestcay asway eldhay onay 10htay ovemberNay, 2001 atay UET
Bay.
anay aay eyeay Anay Aay Eyeay eeBay EEBay hakaDay-1205 1tsay astlay.
492 run time error help plz
Posted: Wed Dec 17, 2008 8:39 pm
by sazzadcsedu
i got run time error .
but why???
cant understand!!
here is my code.
Code: Select all
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main()
{
int i,alph,flag,pos,k,len;
char str[100000];
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
while(gets(str))
{
alph=0;
for(i=0;str[i];i++)
{
if(isalpha(str[i]))
{
if(alph==0)
{
pos=i;
}
alph=1;
}
else if(!isalpha(str[i]) && alph==1)
{
if((str[pos]=='a') || (str[pos]=='e') || (str[pos]=='i') || (str[pos]=='o') || (str[pos]=='u') || (str[pos]=='A') || (str[pos]=='I') || (str[pos]=='E') || (str[pos]=='O') || (str[pos]=='U'))
flag=1;
else
flag=0;
alph=0;
if(flag==1)
{
for(k=pos;k<i;k++)
{
printf("%c",str[k]);
}
printf("ay%c",str[i]);
}
else
{
for(k=pos+1;k<i;k++)
{
printf("%c",str[k]);
}
printf("%cay%c",str[pos],str[i]);
}
}
else
printf("%c",str[i]);
}
len=strlen(str)-1;
if(isalpha(str[len]))
{
if((str[pos]=='a') || (str[pos]=='e') || (str[pos]=='i') || (str[pos]=='o') || (str[pos]=='u') || (str[pos]=='A') || (str[pos]=='I') || (str[pos]=='E') || (str[pos]=='O') || (str[pos]=='U'))
{
for(k=pos;k<i;k++)
{
printf("%c",str[k]);
}
printf("ay");
}
else
{
for(k=pos+1;k<i;k++)
{
printf("%c",str[k]);
}
printf("%cay",str[pos]);
}
}
printf("\n");
}
return 0;
}
Re: 492 WA help plz
Posted: Wed Dec 17, 2008 9:21 pm
by Articuno
Make your array size 1000000.
Declare it as global.
And you should use long instead of int. Rest of the code is ok I think.
Good luck
Re: 492 WA help plz
Posted: Wed Dec 17, 2008 9:26 pm
by newkid
@sazzadcsedu
My guess is
there might be more than 100000 characters in one line..
Reading character by character is another alternative. Or you can try with increasing the limit..
Re: 492 WA help plz
Posted: Wed Dec 17, 2008 10:33 pm
by sazzadcsedu
newkid says:
there might be more than 100000 characters in one line..
Reading character by character is another alternative. Or you can try with increasing the limit..
but i tried with str[500000 /1000000].
but the result is same .
run time error.
can u give me a input file???
Re: 492 WA help plz
Posted: Wed Dec 17, 2008 10:46 pm
by Articuno
@ sazzadcsedu,
Just change this portion of your code:
into this:
You will get AC.

Re: 492 WA help plz
Posted: Wed Dec 17, 2008 11:03 pm
by newkid
LMY wrote:Here is my code.
I try some input by the wa discuss topic before but still get wa
can someone help me plz !!
Code: Select all
#include <iostream>
#define MAX 1000000
int main(){
char s[MAX];
while (cin.getline(s, MAX)){
begin = true;
//vowel = true;
The input file has more than 10^6 characters per line..
you were getting WA instead of RTE because you used "cin.getline(s, MAX)" which is arraysafe..
you would have got RTE if you used gets(s)..
Re: 492 WA help plz
Posted: Wed Dec 17, 2008 11:07 pm
by newkid
@sazzadcsedu
Code: Select all
#include <stdio.h>
#include <assert.h>
const long long MAX = 10000000;
int main() {
char ch;
long long cnt;
while (scanf("%c", &ch) == 1) {
cnt = 0;
do {
if (ch == EOF) break;
if (ch == '\n') {
assert(cnt < MAX);
break;
}
cnt++;
} while (scanf("%c", &ch) == 1);
}
return 0;
}
with MAX = 1000000 this code gets RTE
with MAX = 10000000 this gets WA as expected
so update your arraysize to 10^7 or use scan character by character..
Re: at last accepted
Posted: Thu Dec 18, 2008 1:12 am
by sazzadcsedu
thanx to @articuno.
i did according to ur tips &&&& got accepted.
also thanx to @newkid for ur help.
Re: 492 WA help plz
Posted: Thu Dec 18, 2008 1:21 am
by Articuno
@sazzadcsedu
Don't forget to remove your code.
Good luck
492 RTE: PLZZZ HELP ......................
Posted: Sat Jan 10, 2009 9:49 pm
by toru
HI every1,
I m trying to accept this code for around 7 days but every time it gives RTE, i increased the array size but stil the same. i attached my code below plzzzz any1 HELP ME..........................
Code: Select all
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define MAX 1000000
int isvowel(char v_in)
{
int flag = 0;
if(v_in=='A' || v_in=='a')
flag=1;
else if(v_in=='E' || v_in=='e')
flag=1;
else if(v_in=='I' || v_in=='i')
flag=1;
else if(v_in=='O' || v_in=='o')
flag=1;
else if(v_in=='U' || v_in=='u')
flag=1;
return flag;
}
int main()
{
char in[MAX], ch;
long i=0, vowel=0, len=0;
while(gets(in))
{
if(strcmp(in, " ")==0)
continue;
len=strlen(in);
for(i=0; i<len; i++)
{
if( isalpha(in[i]) )
{
ch=in[i++];
vowel=isvowel(ch);
if(vowel)
printf("%c", ch);
while(isalpha(in[i]) && i<len)
{
printf("%c", in[i]);
i++;
}
if(!vowel)
printf("%c", ch);
printf("ay");
i--;
}
else
printf("%c", in[i]);
}
printf("\n");
}
return 0;
}

492: WA, dont know why...
Posted: Tue Jan 13, 2009 2:22 am
by BTMouseKing
Hi all, I have read all the threads on 492 and tried every method and sample inputs/outputs given in previous posts. However, my code still still gets WA. I don't know wats wrong. I'm wondering about the definition of the 'word' (consecutive sequence of letters). Will 'a' be considered as a word? If the input is "This is a man." Will the output be "hisTay isay a anmay." or "hisTay isay aay man."?
Here is my code:
Code: Select all
#include "iostream"
#include "string.h"
using namespace std;
int type_character(char c)
{
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) return 1;
else return 0;
}
int is_vowel(char c)
{
if(c == 'a' || c == 'A' || c == 'e' || c == 'E' ||
c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U') return 1;
else return 0;
}
int main()
{
string input;
string output;
char input_ch[1000000];
char temp_ch[1000] = {};
int temp_ch_index = 0;
char temp[2] = {};
char record;
fflush(stdin);
while (getline(cin,input))
{
output = "";
input += ".";
strcpy(input_ch,input.c_str());
for (long i=0;i<input.length();i++)
{
if (type_character(input_ch[i]))
{
temp_ch[temp_ch_index] = input_ch[i];
temp_ch_index++;
}
else
{
if(temp_ch[0] == '\0') ;
else
{
if (is_vowel(temp_ch[0])) ;
else
{
record = temp_ch[0];
for (int j=0;j<temp_ch_index-1;j++)
temp_ch[j] = temp_ch[j+1];
temp_ch[temp_ch_index-1] = record;
}
output += temp_ch;
output += "ay";
}
temp[0] = input_ch[i];
output += temp;
temp_ch_index = 0;
memset(temp_ch,0,1000);
}
}
output = output.substr(0,output.length()-1);
cout << output << endl;
memset(input_ch,0,1000000);
}
return 0;
}
Re: 492 WA: tell me why ........................
Posted: Sun Jan 18, 2009 9:27 pm
by theharshest
I am getting WA for the following code.. Pease help..
Code: Select all
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s,str;
long long c,t,i;
while(getline(cin,s))
{
c=0;
while(c<s.length())
{
if(c==0)
t=s.find(" ",c);
else
t=s.find(" ",c+1);
//cout<<c<<" "<<t<<endl;
str=s.substr(c,t-c+1);
//cout<<str<<endl;
if(str[0]=='a' || str[0]=='e' || str[0]=='i' || str[0]=='o' || str[0]=='u' || str[0]=='A' || str[0]=='E' || str[0]=='I' || str[0]=='O' || str[0]=='U' )
{
if((str[str.length()-1]>=65 && str[str.length()-1]<=90) || (str[str.length()-1]>=97 && str[str.length()-1]<=122))
{
cout<<str<<"ay";
}
else
{
for(i=0;i<str.length()-1;i++)
cout<<str[i];
cout<<"ay"<<str[str.length()-1];
}
}
else
{
if((str[str.length()-1]>=65 && str[str.length()-1]<=90) || (str[str.length()-1]>=97 && str[str.length()-1]<=122))
{
for(i=1;i<str.length();i++)
cout<<str[i];
cout<<str[0]<<"ay";
}
else
{
for(i=1;i<str.length()-1;i++)
cout<<str[i];
cout<<str[0]<<"ay"<<str[str.length()-1];
}
}
c+=str.length();
}
cout<<endl;
}
}
Re: 492 WA: tell me why ........................
Posted: Mon Jan 19, 2009 12:44 am
by mf
Note this sentence:
A ``word'' is defined as a consecutive sequence of letters (upper and/or lower case).
So, words might not be separated by spaces. In fact there may be no single space in the input. For example, the following input has four words:
Re: 492 - Pig Latin
Posted: Wed Feb 18, 2009 8:50 pm
by qwerty
ac..removed