Page 7 of 15

Posted: Fri Jun 17, 2005 7:30 am
by emotional blind
now remove this code immidiately
never send your ACC code here

Posted: Fri Sep 16, 2005 12:00 am
by Jan
Change your my_p() function.

Code: Select all

int my_p(char ch) 
{ 
    if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')) 
        return 0; 
    else 
        return 1; 
} 
Hope it works.

Posted: Fri Sep 16, 2005 12:34 am
by Jan
I don't know pascal. But I can say that this problem requires a big array. My array size was 1000000.

Hope it helps.

492 Wrong Answer why ??

Posted: Thu Oct 20, 2005 3:19 pm
by late_nighter
Iam getting wrong answer for the 492 question. I have checked most of the
cases I can think of .

<code>

#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main ()
{
string x = "";
char ch;
while ((ch = getchar ()) != EOF)
{
if (isalpha (ch))
{
x+= ch;
}
else{
if ( toupper (x[0]) == 'A' ||
toupper (x[0]) == 'E' ||
toupper (x[0]) == 'I' ||
toupper (x[0]) == 'O' ||
toupper (x[0]) == 'U'
)
{
x+= "ay";
}else
{
if (x!="")
{
char c = x[0];
x = x.substr(1,x.size()-1);
x+=c;
x+="ay";
}
}
cout << x ;
cout << ch ;
x = "";
}
}

if (x!= "")
{
if ( toupper (x[0]) == 'A' ||
toupper (x[0]) == 'E' ||
toupper (x[0]) == 'I' ||
toupper (x[0]) == 'O' ||
toupper (x[0]) == 'U'
)
{
x+= "ay";
}else
{
if (x!="")
{
char c = x[0];
x = x.substr(1,x.size()-1);
x+=c;
x+="ay";
}
}
cout << x ;
cout << ch ;
x = "";

}
}

</code>

Can anyone tell me for which case is the program failing??

Posted: Thu Oct 20, 2005 8:03 pm
by Solaris
before checking

toupper(x[0]) == SOMETHING

u should check whether x == "" or not

492-- Why I Get WA ??? Please Help...

Posted: Sat Dec 10, 2005 7:42 pm
by jan_holmes
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <cstring>

// Wrong Answer ... :(

using namespace std;

int main () {
char n[2000000];
string x;
string ret;
while(cin.getline(n,2000000)) {
ret = "";
x = "";
for (int i=0;n;i++) {
if (isalpha(n)) x+=n;
else {
if (x == "") ret+=n;
else {
if (x[0] == 'A' || x[0] == 'E' || x[0] == 'I' || x[0] == 'O' || x[0] == 'U') {
for (int j=0;x[j];j++) {
ret+=x[j];
}
ret+="ay";
ret+=n;
x = "";
}
else if (x[0] == 'a' || x[0] == 'e' || x[0] == 'i' || x[0] == 'o' || x[0] == 'u') {
for (int j=0;x[j];j++) {
ret+=x[j];
}
ret+="ay";
ret+=n;
x = "";
}
else {
for (int j=1;x[j];j++) {
ret+=x[j];
}
ret+=x[0];
ret+="ay";
ret+=n;
x = "";
}
}
}
}
if (x != "") {
if (x[0] == 'A' || x[0] == 'E' || x[0] == 'I' || x[0] == 'O' || x[0] == 'U') {
for (int j=0;x[j];j++) {
ret+=x[j];
}

ret+="ay";
x = "";
}
else if (x[0] == 'a' || x[0] == 'e' || x[0] == 'i' || x[0] == 'o' || x[0] == 'u') {
for (int j=0;x[j];j++) {
ret+=x[j];
}

ret+="ay";
x = "";
}
else {
for (int j=1;x[j];j++) {
ret+=x[j];
}
ret+=x[0];
ret+="ay";
x = "";
}
}

cout << ret << "\n";
}
return 0;
}

492 WA!!WHO CAN GIVE ME SOME TEST DATA??!!THANKS A LOT

Posted: Tue Mar 21, 2006 12:30 pm
by Staryin

Code: Select all

#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctype.h>
using namespace std;
char c[10000000];
char *word[10000];
int i,j,k,cnt,len;
char *p;
char punc;
void solve()
{
	 punc='\0';
	 len=strlen(word[cnt-1]);
	 for(i=0;i<len;i++)
	 	if(!isalpha(word[cnt-1][i]))
	 		{
	 			punc=word[cnt-1][i];
				len=len-1;
			}
	
	 if(word[cnt-1][0]=='a'||word[cnt-1][0]=='A'||word[cnt-1][0]=='e'
				 	||word[cnt-1][0]=='E'||word[cnt-1][0]=='i'||word[cnt-1][0]=='I'
				 	||word[cnt-1][0]=='O'||word[cnt-1][0]=='o'||word[cnt-1][0]=='u'
				 	||word[cnt-1][0]=='U')
				{
					
					for(k=0;k<len;k++)
						cout<<word[cnt-1][k];	
					cout<<"ay";
					cout<<punc;
					cout<<" ";
				}		
				else
				{
					
					for(k=1;k<len;k++)
						cout<<word[cnt-1][k];
					cout<<word[cnt-1][0]<<"ay";
					cout<<punc;
					cout<<" ";
				
				}
	

}
void deal()
{
	cnt=0;
	p = strtok(c," "); 
	if (p)
		{
			word[cnt++]=p;  
			solve();
			
		}
	while(p)
	{
		p = strtok(NULL," ");  

	 if (p)
	 	 {
	 	 	word[cnt++]=p;
	 	 	solve(); 
	 	} 
	}
	cout<<endl;
}
void read()
{
		while(gets(c))
			deal();
}
int main()
{
	read();
	return 0;	
}

Posted: Sun Mar 26, 2006 5:38 am
by chunyi81
Try this input:

Code: Select all

This  is  the  input.
This.is.the.input.
2 spaces separate each word for the first line.
And for the second line, the period '.' separates each word.

Your code will fail for these test cases because you used strtok. You are assuming only 1 space separate each word.

The problem description says:
A "word" is defined as a consecutive sequence of letters (upper and/or lower case)
It does not mean the words are separated by exactly 1 space.

There are test cases in past threads. Just do a search for 492.

Explain a difference

Posted: Fri Jun 09, 2006 9:35 am
by Zaspire
Explain a difference
A get AC with this code(492)
#include <stdio.h>
#include <ctype.h>

int alpha(int c)
{
if ((c>='A'&&c<='Z')||(c>='a'&&c<='z')) return 1;
return 0;
}

int main()
{
int c,last,t;
c=getchar();
while (c!=EOF)
{
last=tolower(c);
if (alpha(c)) t=1;
else t=0;
if ((t==1)&&(!((last=='a')||(last=='e')||(last=='i')||(last=='o')||(last=='u')))) {last=c; c=getchar();}
else last=0;
while (alpha(c))
{
putchar(c);
c=getchar();
}
if (last!=0) putchar(last);
if (t==1) {putchar('a');putchar('y');}
if (c!=EOF) {putchar(c); c=getchar();}
}
return 0;
}

Posted: Fri Jun 09, 2006 9:36 am
by Zaspire
And get WA with this:
#include <stdio.h>
#include <string>
#include <ctype.h>

int alpha(int c)
{
if ((c>='A'&&c<='Z')||(c>='a'&&c<='z')) return 1;
return 0;
}

int main()
{
int c,last;
std::string str;
c=getchar();
while (c!=EOF)
{
str="";
last=tolower(c);
if (alpha(c)&&(!((last=='a')||(last=='e')||(last=='i')||(last=='o')||(last=='u')))) {last=c; c=getchar();}
else last=0;
while (alpha(c))
{
str+=(char)c;
c=getchar();
}
if (last!=0) str+=(char)last;
if (str!="") str+="ay";
printf("%s",str.data());
if (c!=EOF) {putchar(c); c=getchar();}
}
return 0;
}

Posted: Fri Jun 09, 2006 6:59 pm
by Martin Macko
Zaspire wrote:And get WA with this:

Code: Select all

		...
		printf("%s",str.data());
		...
str.data() does not have to be terminated by 0. Use str.c_str() instead.

Posted: Sat Jun 10, 2006 11:02 am
by Zaspire
Why on my computer (Visual Studio 2005) this code work?

Posted: Sat Jun 10, 2006 5:53 pm
by Martin Macko
Zaspire wrote:Why on my computer (Visual Studio 2005) this code work?
I don't know. Possibly, VS2005 has a different implementation of strings than GCC. The STL documentation states:
STL documentation wrote:const charT* data() const: Returns a pointer to an array of characters, not necessarily null-terminated, representing the string's contents. data() is permitted, but not required, to be identical to c_str(). The first size() characters of that array are guaranteed to be identical to the characters in *this. The return value of data() is never a null pointer, even if size() is zero.
Have you already tried to submit that code with str.data() exchanged by str.c_str()? Has it helped?

Posted: Sun Jun 11, 2006 3:13 pm
by Zaspire
Thanks for the help.
It has really helped.

Anybody known other different between VS 2005 and GCC?
I like VS 2005. But I have many error because In VS has a different implementation than GCC.

__________
Sorry for my bad English.

Posted: Sun Jun 11, 2006 7:37 pm
by Martin Macko
Zaspire wrote:Anybody known other different between VS 2005 and GCC?
I like VS 2005. But I have many error because In VS has a different implementation than GCC.
I don't know, I've never used VS. It may be helpful for you to compile your solutions also by GCC before submiting. There is a version of GCC for MS windows, too. Look at http://www.mingw.org/.