Page 14 of 15
Re: 492 why RE?
Posted: Fri Feb 15, 2013 8:57 pm
by shipu_a
lbv wrote:shipu_a wrote:
now TLE
Did you read the second comment (the one about
strlen)?
You can try changing this:
for something like this:
Code: Select all
for(int i=0, len = strlen(s);i<len;i++)
Thank you so much...................
uva 492
Posted: Sun Oct 20, 2013 10:07 am
by walking_hell
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;
}
Re: uva 492
Posted: Mon Oct 21, 2013 9:33 pm
by brianfry713
Try reading a char at a time.
Re: why WA?(492)piglatin
Posted: Mon Nov 25, 2013 4:15 pm
by darksk4
Pleace can you tell me why I am getting TLE in this code?
Re: why WA?(492)piglatin
Posted: Mon Nov 25, 2013 11:51 pm
by brianfry713
cin, cout, and passing a string as an argument to a function are slow. Try using getchar() and putchar() instead.
Re: 492 why RE?
Posted: Mon Dec 30, 2013 9:15 pm
by Shihab
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;
}
Re: 492 why RE?
Posted: Thu Jan 16, 2014 12:35 am
by brianfry713
Your code never terminates.
Re: 492 why RE?
Posted: Sun Jan 19, 2014 11:41 am
by Shihab
Thanks, AC
Re: 492 why RE?
Posted: Mon Mar 10, 2014 9:36 am
by uDebug
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
Code: Select all
while(scanf("%[^\n]%*c", aLine) != EOF)
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:
Code: Select all
Apple
This
;'/.,][ -()*&^%$#@!
A a E e o Oo U u i I
The quIck brOwn fOx jumps OVER the LAzy doG .
AC Output:
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?
Posted: Wed May 21, 2014 12:14 pm
by jddantes
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?
Posted: Wed May 21, 2014 12:25 pm
by uDebug
jddantes wrote: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.
Re: 492 why RE?
Posted: Wed May 21, 2014 7:43 pm
by jddantes
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;
}
Re: 492 why RE?
Posted: Wed May 21, 2014 8:22 pm
by brianfry713
Do you need to use memset on every line?
Re: 492 why RE?
Posted: Mon Jul 21, 2014 10:27 am
by sampad74
I am getting RE.Here is my code.Please anybody help..Thanks in advance.
Re: 492 why RE?
Posted: Mon Jul 21, 2014 12:39 pm
by lighted
Increase parameter of array
It must be
You will have TLE.
Try to change
You can do it like this
Code: Select all
#include<stdio.h>
#include<string.h>
..
..
int l = strlen(a);
for(j = 0; j < l; j++)
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