Page 6 of 15

Posted: Fri Jul 23, 2004 9:06 am
by WR
Hi Orojas,

as far as I remember an input line can be VERY long. Try to read the input character by character.

now i get WA ????

Posted: Fri Jul 23, 2004 8:21 pm
by orojas
thanks Wr, changed the code, looks like this:

[c]#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int esVocal(char l) {
l = toupper(l);
if(l=='A' || l=='E' || l=='I' || l=='O' || l=='U')
return 1;
else
return 0;
}

int main() {
char pendiente;
char start;
char cons;
char caracter;
start=0;
while (scanf("%c",&caracter)==1) {
if(isalpha(caracter)) {
if(start==0) {
start=1;
if(esVocal(caracter)) {
printf("%c",caracter);
}
else {
cons = 1;
pendiente=caracter;
}
}
else {
printf("%c",caracter);
}
}
else {
if(start==0) {
printf("%c",caracter);
}
else {
start=0;
if(cons==1) {
cons = 0;
printf("%cay%c",pendiente,caracter);
}
else {
printf("%ay%c",caracter);
}
}
}
}
return 0;
}[/c]

now i get WA, even though i think is ok. I've thinked all possibilities bu dont know what's wrong!!!

492 - WA -> Java Masters Please !! take a look ! :)

Posted: Fri Jul 30, 2004 10:22 pm
by amardeshbd
hi there ?
here is my CODE for which i'm getting WA....
don't b afraid 2 c my code...
bcoz it may seem like an essay......
actually i'm an amature programmer....
n while i was doing this code ! i wanted to finish it any way....
thats why there is so many methods and complexity !...
thats why it RAN for 5.91 seconds and at last got Wrong Answer !....

i'll be greatful if you show me where i'm making the mistake !
or give me some critical I/O.

thanks
@ hossaiN


[java]

class Main
{

static String ReadLn (int maxLg) // read line from buffer
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";

try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}

if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}

static void Begin()
{

String str;
boolean found=true;
int i;

while((str = Main.ReadLn(10000)) != null)
{
str = str.trim();
String onlyWord="";
StringTokenizer stk = new StringTokenizer(str);
while(stk.hasMoreTokens())
{
onlyWord = stk.nextToken();
if(allLetters(onlyWord))
{
System.out.print(encodeLatin(onlyWord));
}
else
{
System.out.print(done(onlyWord));
}
if(stk.hasMoreTokens())
System.out.print(" ");
}
//if(str.charAt((str.length()-1)) == '.')
// System.out.println(".");
System.out.println("");
}
}

static boolean allLetters(String word)
{
for(int i=0; i<word.length(); i++)
{
if(!(Character.isLetter(word.charAt(i))))
return false;
}
return true;
}

static String done(String separate)
{
String donex = "";
int count,end=0,bal=0;
boolean wasLetter = false;
int i,j;
for(i=0;i<separate.length(); )
{

while(i<separate.length() && Character.isLetter(separate.charAt(i)))
{
wasLetter = true;
end = i;
i++;
}
if(wasLetter)
{
j=bal;
String go="";
while(j<=end)
{
go += separate.charAt(j);
j++;
}
donex += encodeLatin(go);
}
while(i<separate.length() &&
!(Character.isLetter(separate.charAt(i))))
{
donex += separate.charAt(i);
i++;
wasLetter = false;
bal = i;
}

}

return donex;

}// end of method

static String deleteLastChar(String word)
{
int i;
char tmp1[] = word.toCharArray();
char tmp2[] = new char[word.length()-1];
for(i=0;i<word.length()-1; i++)
{
tmp2 = tmp1;
}
return (new String(tmp2));
}

static String encodeLatin(String word)
{
// For example, ``apple'' becomes ``appleay''
// For example, ``hello'' becomes ``ellohay''
int wLength = word.length();
String tempWord="";
boolean hasFullStop = (word.charAt(wLength-1) == '.');
if(hasFullStop)
{
word = deleteLastChar(word);
}
char wArray[] = word.toCharArray();
char rArray[] = new char[wLength];
int j=0;
if(isVowel(word.charAt(0)))
{
tempWord = word + "ay";
if(hasFullStop)
return (tempWord+".");
else return tempWord;
}
else
{
int i;
for(i=1;i<word.length(); i++)
{
rArray[(i-1)] = wArray;
}
rArray[(i-1)] = wArray[0];
String codeWord = new String(rArray);
codeWord += "ay";
codeWord = codeWord.trim();

if(hasFullStop)
return (codeWord+".");
else return codeWord;
}
}

static boolean isVowel(char c)
{
String vowels = "AEIOUaeiou";
for(int i=0; i<vowels.length(); i++)
{
if(vowels.charAt(i) == c)
return true;
}
return false;
}


public static void main(String args[])
{
Main myWork = new Main(); // create a dinamic instance
myWork.Begin(); // the true entry point
}

}

[/java]

thanks once again for your patience !

Posted: Mon Aug 02, 2004 11:24 am
by WR
Hi Orojas,

your output:

Code: Select all

hisTay is%ay%chetay input%ay%c
eHay is%ay%ca%ay%coybay.

Object%ay%c23oriented%ay%c..,.rogrammingPay
000000000
aaaaaaaaaaaa%ay%cAaaaaaaaaaaa%ay%computerprogrammingIIcay
secay-1205 omputerCay rogrammingpay II%ay%c
my output:

Code: Select all

hisTay isay hetay inputay.
eHay isay aay oybay.

Objectay123orienteday,..,.rogrammingPay
000000000
aaaaaaaaaaaaay
Aaaaaaaaaaaaay
omputerprogrammingIIcay
secay-1205 omputerCay rogrammingpay IIay

Posted: Tue Sep 07, 2004 1:58 pm
by Minilek
i have not read all ur code, but i see u make the assumption that each line is no longer than 10,000 characters. i am not sure you can assume this. gl.

P.S.
if any admins see this, i think the juge is missing some critical test inputs for this problem

i wrote a program that did the following and it got AC:

input

Code: Select all

abc123abc
output

Code: Select all

abcay123abc
the correct output should have been

Code: Select all

abcay123abcay

492 - WA

Posted: Tue Jan 25, 2005 7:41 pm
by Racevictor
I have tested all the cases but it also got WA..
Pls give me a helping hand ^^

Code: Select all

//492
#include<iostream>
#include<ctype.h>
using namespace std;
char a[9999];
int main(){
    int i;
    char temph;
    
    while(cin.getline(a,9999)){
       i=0;
       while(1){
          while(!isalpha(a[i])&& a[i]!='\0')cout<<(a[i++]);   
          if(a[i]=='\0')break;
          if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u'||
            a[i]=='A'||a[i]=='E'||a[i]=='I'||a[i]=='O'||a[i]=='U')
          {
              while(isalpha(a[i]))cout<<a[i++];
              cout<<"ay";
          }
          else 
          {
              temph=a[i++];
              while(isalpha(a[i]))cout<<a[i++];
              cout<<temph<<"ay";
          }
           if(a[i]=='\0')break;
       }  
       cout<<endl;  
              
    }    
    return 0;
}    
        
    

piglatin probs

Posted: Wed Jan 26, 2005 9:22 am
by himel
:cry: i used gets it says runtime error but my solution is correct don know why, anyone help me? herez my code:

#include<stdio.h>
#include<string.h>
char s[15000],t[15000];
int a,i,j,b;
void main(){
while(gets(s)){
a=strlen(s);
for(j=0;j<a;j++){
t[j]=NULL;
}
for(i=0;i<a;i++){
if((s>='A'&&s<='Z')||(s>='a'&&s<='z'))
t[i+1]=s;
else
t[i+1]=' ';
}
t[0]=' ';
for(i=1;i<a+1;i++){
if(t!=' '){
if(t[i-1]==' '){
if(t=='A'||t=='E'||t=='I'||t=='O'||t[i]=='U'||t[i]=='a'||t[i]=='e'||t[i]=='i'||t[i]=='o'||t[i]=='u'){
printf("%c",s[i-1]);
b=0;}
else
b=s[i-1];
}
else
printf("%c",s[i-1]);
}
else{
if(t[i-1]!=' '){
if(b==0)
printf("ay%c",s[i-1]);
else{
printf("%cay%c",b,s[i-1]);
b=0;}
}
else
printf("%c",s[i-1]);
}
}
if(t[a]!=' '){
if(b==0)
printf("ay");
else
printf("%cay",b);
}
printf("\n");
}
}

492-Pig-latin: plz find out the WA.

Posted: Sun Jan 30, 2005 9:42 am
by ahmed hasan
For using getline(cin,ip) this program does not run in vc++ properly.
I used mingw.

Code: Select all

#include<iostream>
#include<string>
#include<cstring>

using std::string;
using std::cout;
using std::endl;
using std::cin;
using std::getline;

string ip;
string vowel("AEIOUaeiou");
int p1,p2;
int fsf;
int l;

string word_process(string word)
{
    if(word==".")return word;

    fsf=0;
    if(word.at(word.length()-1)=='.')
    {word.erase(word.length()-1);fsf=1;}

    if(vowel.find(word[0])==string::npos)
    {word+=word[0];word.erase(0,1);}
    word+="ay";
    if(fsf)word+=".";        
    return word;
    
}



int main()
{
    while(getline(cin,ip))
    {
        p1=p2=0;
        while(1)
        {
            while(p1<ip.length()&&ip[p1]==' ')p1++;p2=p1;
            if(p1>=ip.length())break;
            while(p2<ip.length()&&ip[p2]!=' ')p2++;
            ip.replace(p1,p2-p1,word_process(ip.substr(p1,p2-p1)));
            while(p2<ip.length()&&ip[p2]!=' ')p2++;p1=p2;
        }
        cout<<ip<<endl;
    }
    return 0;
}


Posted: Tue Feb 01, 2005 1:54 pm
by mohiul alam prince
Hi
u have processed for ur programm one input and one new line for one
out put but the programm should have to do one input for one output.

MAP

TLE!!!!!! Very Strange

Posted: Fri Feb 11, 2005 5:05 pm
by ahmed hasan
Got TLE for 492-Pig-Latin
PLZ any body explain
For using getline(cin,string) it does not run in VC++ properly.
I have used MINGW.

Code: Select all

//this program run only in mingw;
#include<iostream>
#include<string>

using std::string;
using std::cout;
using std::endl;
using std::cin;
using std::getline;

string ip;
string vowel("AEIOUaeiou");

string WordProcess(string word)
{
    if(vowel.find(word[0])==string::npos)
        {word+=word[0]; word.erase(0,1);}
    return word+"ay";
}

int main()
{
	int p1,p2;
    while(getline(cin,ip))
    {
        p1=p2=0;
		while(1)
		{
			while(p1<ip.length() && !isalpha(ip[p1]))p1++;
			if(p1>=ip.length())break;
			p2=p1;
			while(p2<ip.length() && isalpha(ip[p2]))p2++;
			ip.replace(p1,p2-p1,WordProcess(ip.substr(p1,p2-p1)));
			p1=p2+2;
        }
		cout<<ip<<endl;
	}
    return 0;
}

Posted: Sun Feb 13, 2005 1:38 pm
by mohiul alam prince
hi
when i wanted to solve this problem i took input with gets and got TLE
but when i took input in only one char wise that time i got AC

MAP

plz say me why i get WA at 492 ???

Posted: Thu Mar 31, 2005 7:48 pm
by thinker
please say me what is my wrong. no need to give your solve. just see my solve and say what my wrong and how i recover it. my code is following.

#include<iostream>
#include<stdio.h>
#include<string>

using namespace std;

string str1;
string str2=" ";
char s[5000000];
char pn[200000];
char ch;
int j=0;


int isvl(char cc)
{
cc=toupper(cc);

if(cc=='A'||cc=='E'||cc=='I'||cc=='O'||cc=='U')
return 1;
else
return 0;
}


int my_p(char ch)
{
if(((ch>='!')&&(ch<='@'))||((ch>='[')&&(ch<='`')))
return 1;
else
return 0;
}



int main()

{
// freopen("input.in","r",stdin);
while(gets(s)!=NULL)
{

str1=s;
str1=str1+str2;
int l=0;
int pos=str1.find(' ');
int last=str1.find_last_of(str1);


while(pos!=last)
{
if((isvl(str1.at(l)))==1)
{
for(int i=l;i<pos;i++)
{
if((my_p(str1.at(i)))==1)
{
pn[j]=str1.at(i);
}
else
cout<<str1.at(i);

}
printf("ay");
printf("%c",pn[j]);
j=j+1;
}

else
{
ch =str1.at(l);

for(int i=l+1;i<pos;i++)
{
if((my_p(str1.at(i)))==1)
{
pn[j]=str1.at(i);

}
else
cout<<str1.at(i);
}
printf("%cay",ch);
printf("%c",pn[j]);
j=j+1;
}

l=pos+1;
pos=str1.find(' ',pos+1);
}
printf("\n");
}
return 0;
}

492 WA

Posted: Sun Jun 12, 2005 2:17 pm
by swpeng
why I got WA? I had tried all the cases....

Code: Select all

#include<iostream>

using namespace std;


const int cmax=150000;
char ch[cmax+1];
int chx;

void anaout();
bool isv(char);

int main(){
	char chline[cmax+1];
	int x;
	while(cin.getline(chline,cmax)){
		for(x=0,chx=0;;x++){
			if((chline[x]>=0x41 && chline[x]<=0x5A) || (chline[x]>=0x61 && chline[x]<=0x7A)){
				ch[chx]=chline[x];
				chx++;
			}
			else{
				ch[chx]=0x00;
				if(chx!=0)
					anaout();
				cout<<chline[x];
				chx=0;
			}

			if(chline[x]==0x00)
				break;
		}
		cout<<endl;
	}
	return 0;
}

void anaout(){
	int x;
	//analyze
	if(isv(ch[0])){
		cout<<ch<<"ay";
	}
	else{
		for(x=1;ch[x]!=0x00;x++){
			cout<<ch[x];
		}
		cout<<ch[0]<<"ay";
	}
}

bool isv(char chisv){
	if(chisv=='A' || chisv=='E' || chisv=='I' || chisv=='O' || chisv=='U' || chisv=='a' || chisv=='e' || chisv=='i' || chisv=='o' || chisv=='u')
		return true;
	return false;
}

Posted: Tue Jun 14, 2005 12:03 pm
by emotional blind
the input line may be very long
more than 150000 :cry:
i think you cannot fix it with an array
try to take input character by character or word by word..
hope your success
keep posting

Posted: Wed Jun 15, 2005 8:57 pm
by swpeng
thanks....I fixed the code and submitted it again, and I got AC!

(No array)

Code: Select all

#include<iostream>

using namespace std;

bool isv(char);

int head;

int main(){
	char w,wal;
	head=0;
	while(cin.get(w)){
		if((w>=0x41 && w<=0x5A) || (w>=0x61 && w<=0x7A)){
			if(head==0){
				if(isv(w)){
					head=1;
					cout<<w;
				}
				else{
					head=2;
					wal=w;
				}
			}
			else{
				cout<<w;
			}
		}
		else{
			if(head!=0){
				if(head==2)
					cout<<wal<<"ay";
				else
					cout<<"ay";
				head=0;
			}
			cout<<w;
		}
	}
	return 0;
}


bool isv(char chisv){
	if(chisv=='A' || chisv=='E' || chisv=='I' || chisv=='O' || chisv=='U' || chisv=='a' || chisv=='e' || chisv=='i' || chisv=='o' || chisv=='u')
		return true;
	return false;
}