Thank you so much...................lbv wrote:Did you read the second comment (the one about strlen)?shipu_a wrote: now TLE
You can try changing this:for something like this:Code: Select all
for(int i=0;i<strlen(s);i++)
Code: Select all
for(int i=0, len = strlen(s);i<len;i++)
492 - Pig-Latin
Moderator: Board moderators
Re: 492 why RE?
Nothing is imposible in the world.....And
Never Judge a Book by Its Cover.............
BUBT_Psycho
http://uhunt.felix-halim.net/id/168573
http://shipuahamed.blogspot.com
Never Judge a Book by Its Cover.............
BUBT_Psycho
http://uhunt.felix-halim.net/id/168573
http://shipuahamed.blogspot.com
-
- New poster
- Posts: 14
- Joined: Tue Sep 24, 2013 4:35 pm
uva 492
cant find my bug
Code: Select all
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char arr[1000000],word[1000000];
int len,lenw,count,tm;
while(scanf(" %[^\n]",arr)==1)
{
len=strlen(arr);
for(count=0;count<len;count++)
{
if(tolower(arr[count])>='a' && tolower(arr[count])<='z')
{
sscanf(&arr[count]," %[A-Za-z]",word);
lenw=strlen(word);
count+=lenw;
if(tolower(word[0])!='a' &&tolower(word[0])!='e'&&tolower(word[0])!='i'&&tolower(word[0])!='o'&&tolower(word[0])!='u')
{
for(tm=1;tm<lenw;tm++)
printf("%c",word[tm]);
printf("%cay",word[0]);
}
else
printf("%say",word);
}
printf("%c",arr[count]);
}
printf("\n");
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: uva 492
Try reading a char at a time.
Check input and AC output for thousands of problems on uDebug!
Re: why WA?(492)piglatin
Last edited by darksk4 on Tue Nov 26, 2013 6:43 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: why WA?(492)piglatin
cin, cout, and passing a string as an argument to a function are slow. Try using getchar() and putchar() instead.
Check input and AC output for thousands of problems on uDebug!
Re: 492 why RE?
TE , help
Code: Select all
#include <cstdio>
#include <cstring>
#include<iostream>
using namespace std;
int main()
{
char s,c;
int i,j=0,k,flag=0,length,is_s_started,temp;
while(1)
{
//c=getchar();
scanf("%c",&c);
if ((c>= 'a' && c<= 'z') || (c>= 'A' && c<= 'Z') )
{
++j;
if((c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U') && j==1)
{
flag=0;//ckecking for vowel
//putchar(c);
printf("%c",c);
}
else
{
if(j==1)
{
flag=1;
s=c;
//putchar(c);
}
else
{
//putchar(c);
printf("%c",c);
}
}
}
else
{
if(flag==1)
{
flag=0;
//putchar(s);
printf("%c",s);
}
if(j>0)
{
//putchar('a' );
//putchar('y');
printf("ay");
}
//putchar(c);
printf("%c",c);
j=0;
}
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 492 why RE?
Your code never terminates.
Check input and AC output for thousands of problems on uDebug!
Re: 492 why RE?
This is a bit of a weird problem.
For starters, the judge's test seems rather weak. In my mind, if the word
is on a line by itself, the AC output should be
However, UVA Toolkit outputs
Also, I got a runtime error using
where "aLine" is a std::string.
I ended up using
where "aLine" is a char[] with size 1,000,000. There are more than 10,000 characters a line - so be warned. (I got a runtime error with char[] array with a size of 10,000).
That being said, here's some input / output I found useful.
Input:
AC Output:
For starters, the judge's test seems rather weak. In my mind, if the word
Code: Select all
Apple
Code: Select all
Appleay
Code: Select all
Apple
Code: Select all
while(getline(cin, aLine)
I ended up using
Code: Select all
while(scanf("%[^\n]%*c", aLine) != EOF)
That being said, here's some input / output I found useful.
Input:
Code: Select all
Apple
This
;'/.,][ -()*&^%$#@!
A a E e o Oo U u i I
The quIck brOwn fOx jumps OVER the LAzy doG .
Code: Select all
Appleay
hisTay
;'/.,][ -()*&^%$#@!
Aay aay Eay eay oay Ooay Uay uay iay Iay
heTay uIckqay rOwnbay Oxfay umpsjay OVERay hetay AzyLay oGday .
Re: 492 why RE?
Why RE?
Code: Select all
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void strapp(char * dest, char * src);
void processWord(char * word);
int isVowel(char c);
int main(){
char raw[10000000];
while(fgets(raw,10000000,stdin)!=NULL){
//printf("Got input: %s", raw);
if(raw[strlen(raw)-1]=='\n')
raw[strlen(raw)-1] = 0;
char decoded[10000000] = {};
//printf("Decoded: %s\n",decoded);
char word[100000];
memset(word,0,100000);
int i = 0;
int wordindex = 0;
for(i=0; 1;i++){
if(!isalpha(raw[i])){
// Process word
processWord(word);
//printf("Word is now %s\n",word);
strapp(decoded, word);
//printf("Decoded:%s\n",decoded);
if(raw[i]==0)
break;
//Append this character
char cword[5];
cword[0]=raw[i];
cword[1]=0;
strapp(decoded,cword);
wordindex = 0;
memset(word,0,100000);
//printf("Decoded2: %s\n",decoded);
} else {
word[wordindex] = raw[i];
word[wordindex+1] = 0;
//puts(word);
wordindex++;
}
}
//printf("Processed string: %s\n",decoded);
printf("%s\n",decoded);
}
return 0;
}
void strapp(char * dest, char * src){
int len = strlen(dest);
strcpy(dest+len,src);
}
void processWord(char * word){
if(word[0]==0)
return;
if(isVowel(word[0])){
//printf("Vowel\n");
strapp(word,"ay");
return;
} else {
char temp[100000];
strcpy(temp,word+1);
char t[5];
t[0]=word[0];
t[1]=0;
strapp(temp,t);
strapp(temp, "ay");
strcpy(word,temp);
}
//printf("done: %s\n",word);
}
int isVowel(char c){
char x = tolower(c);
if(x=='a' || x=='e' || x=='i' || x=='o' || x=='u'){
//printf("%c is a vowel\n",c);
return 1;
}
//printf("%c is not a vowel\n",c);
return 0;
}
Re: 492 why RE?
10,000,000 bytes is ~9.5 MB and the stack has only ~1 MB. If you really need that much place, try making the array of characters global in scope.jddantes wrote:Why RE?
Re: 492 why RE?
Okay thanks for that. I got TLE now though. Is strapp causing this? (It uses strlen)
Code: Select all
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void strapp(char * dest, char * src);
void processWord(char * word);
int isVowel(char c);
char raw[1000000];
char decoded[1000000];
int main(){
memset(raw, 0, 1000000);
while(fgets(raw,1000000,stdin)!=NULL){
//printf("Got input: %s", raw);
if(raw[strlen(raw)-1]=='\n')
raw[strlen(raw)-1] = 0;
memset(decoded, 0, 1000000);
//printf("Decoded: %s\n",decoded);
char word[100000] = {};
int i = 0;
int wordindex = 0;
for(i=0; 1;i++){
if(!isalpha(raw[i])){
// Process word
processWord(word);
//printf("Word is now %s\n",word);
strapp(decoded, word);
//printf("Decoded:%s\n",decoded);
if(raw[i]==0)
break;
//Append this character
char cword[5];
cword[0]=raw[i];
cword[1]=0;
strapp(decoded,cword);
wordindex = 0;
memset(word,0,100000);
//printf("Decoded2: %s\n",decoded);
} else {
word[wordindex] = raw[i];
word[wordindex+1] = 0;
//puts(word);
wordindex++;
}
}
//printf("Processed string: %s\n",decoded);
printf("%s\n",decoded);
memset(raw, 0, 1000000);
}
return 0;
}
void strapp(char * dest, char * src){
int len = strlen(dest);
strcpy(dest+len,src);
}
void processWord(char * word){
if(word[0]==0)
return;
if(isVowel(word[0])){
//printf("Vowel\n");
strapp(word,"ay");
return;
} else {
char temp[100000];
strcpy(temp,word+1);
char t[5];
t[0]=word[0];
t[1]=0;
strapp(temp,t);
strapp(temp, "ay");
strcpy(word,temp);
}
//printf("done: %s\n",word);
}
int isVowel(char c){
char x = tolower(c);
if(x=='a' || x=='e' || x=='i' || x=='o' || x=='u'){
//printf("%c is a vowel\n",c);
return 1;
}
//printf("%c is not a vowel\n",c);
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 492 why RE?
Do you need to use memset on every line?
Check input and AC output for thousands of problems on uDebug!
Re: 492 why RE?
I am getting RE.Here is my code.Please anybody help..Thanks in advance.
Code: Select all
got AC
Last edited by sampad74 on Tue Jul 22, 2014 4:59 am, edited 1 time in total.
Re: 492 why RE?
Increase parameter of array
It must be
You will have TLE.
Try to change
You can do it like this
Now you can remove this. It is reason why you will have TLE.
You will have OLE. Your program will run with infinite loop
When will your program end? At which condition?
Read posts in this thread first
Code: Select all
char a[100000];
Code: Select all
char a[1000000];
Try to change
Code: Select all
for(j=0;a[j];j++)
Code: Select all
#include<stdio.h>
#include<string.h>
..
..
int l = strlen(a);
for(j = 0; j < l; j++)
Code: Select all
for(i=0;i<100000;i++) a[i]='\0';
Code: Select all
while(1)
{
gets(a);
..
..
}
Read posts in this thread first
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman