## 576 - Haiku Review

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

### 576 - Haiku Review

It seems that I keep getting wrong answer, but I tested the test cases and it worked perfectly.

Any suggestions? Thanks.

arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia
what about sequencing a,e,i,o,u,y?

Code: Select all

``````bbbbbybbbbb cccccyccccc dddddyddddd fffffyfffff gggggyggggg/hhhhhahhhhh jjjjjajjjjj kkkkkakkkkk lllllalllll mmmmmammmmm nnnnnannnnn pppppappppp/qqqqqiqqqqq rrrrrirrrrr sssssisssss tttttittttt vvvivvv

axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxi

aiiiiiiiiiiiaaaaaaaaaiiiuuuuuyyyyyyyy/ aaaaaai        rttttttuuuuuuuuuyy/wwwwawwww
``````

Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

### Answer

What do you mean by sequencing a,e,i,o,u,y?

Is the answer: 3,1,1 ??

Thanks.

arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

### Re: Answer

Ming Han wrote:What do you mean by sequencing a,e,i,o,u,y?

Is the answer: 3,1,1 ??

Thanks.
sequencing like this: aaaaiiiiuuueeeoooo
but i think you've handled it correctly.

anyway, the answer should be Y,1,1

maybe you could tell me your algo?

Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

### WA

Ok, I get Y,1,1

However, I still get wrong answer!

Maybe you can look at my code:

[cpp]// ACM Problem 576
// Haiku Review
// Done by Teh Ming Han

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

int check(char ch){
if (ch=='a') return 1;
if (ch=='e') return 1;
if (ch=='i') return 1;
if (ch=='o') return 1;
if (ch=='u') return 1;
if (ch=='y') return 1;
return 0; //got=0;
}

int main(){
char dat[250];
int i;

while(gets(dat)){
if (strlen(dat)==5)//checks for eof
if (dat[0]=='e'&&dat[1]=='/'&&dat[2]=='o'&&dat[3]=='/'&&dat[4]=='i')
break;

int line[3]={0},li=1,let=0,got;

for (i=0;i<strlen(dat);i++){
got = check(dat);
if (got==1 && let==0){
let=1;
line[li]++;
}else let=0;
if (dat=='/'){
li++;
let = 0;
}
}

if (line[1]!=5) printf("%d\n",1);
else if (line[2]!=7) printf("%d\n",2);
else if (line[3]!=5) printf("%d\n",3);
else printf("Y\n");
}
return 0;
}[/cpp]

Thanks alot.

I have send this in at least 5 times and still get wrong answer.
The judge says: Your program has not solved the problem. It ran during 0.000 seconds.

Noim
Learning poster
Posts: 88
Joined: Sun Oct 13, 2002 6:11 am
Location: Bangladesh
Ming Man ,
Are you really getting WR or Run Time error. You are declaring line[3] but accessing with line[1] line[2] line[3] which is suppose to be line[0], line[1], line[2].

By the by what is the output of the input:

a e i o u / a e i o u i o/ a e i o u

The answer is Y but you are giving 3.
there is a problem in the third portion of your program.
__nOi.m....

rbuchan
New poster
Posts: 27
Joined: Fri Feb 28, 2003 7:59 am
Contact:

### Wrong Answer???

Well, the judge claims that I have a wrong answer, but I can't see it . If anyone else can, let me know.

[cpp]
#include <stdlib.h>
#include <string.h>
#include <iostream.h>

#define MAX_SIZE 256

char inLine[MAX_SIZE];

bool isVowel(char c) {
return ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') ||
(c == 'u') || (c == 'y'));
}

int main() {
int i, verse;
int syllables;
bool vowel_seq;
int sz[3] = {5, 7, 5};

cin.getline(inLine, MAX_SIZE);
while (strcmp(inLine, "e/o/i") != 0) {

// initialize
syllables = 0;
vowel_seq = false;
verse = 0;

// loop through the string
for (i = 0; i < strlen(inLine); i++) {
if (isVowel(inLine) && !vowel_seq) {
vowel_seq = true;
syllables++;
}
else {
vowel_seq = false;
if (inLine == '/') {
if ((verse < 2) && (syllables != sz[verse])) {
break;
}
syllables = 0;
verse++;
}
}
}

// check if they all match
if ((i == strlen(inLine)) && (syllables == 5)) {
cout << "Y" << endl;
}
else {
cout << verse+1 << endl;
}
cin.getline(inLine, MAX_SIZE);
}
return 0;
}
[/cpp]

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:
Would anyone know why something like:
[cpp]sscanf (buf, "%[^/]/%[^/]/%[^]", line[0], line[1], line[2]);[/cpp]
gets WA, where line is an array of character arrays and buf one line from the file, but something like:

[cpp]char *split (char *s)
{
// -- variable declarations --
char *p;

// -- find a slash --
for (p = s; *(p) != '/'; p++)
{ ; }

// -- NUL-terminate the string here --
*(p) = '\0';

// -- return where the next string starts --
return p+1;
}

...

line[0] = buf;
line[1] = split (line[0]);
line[2] = split (line[1]);[/cpp]
gets AC (line is now an array of character pointers).

They *should* do the same thing I think. I've checked the case where the input might have two slashes together, which would sscanf not to update the pointers, but there are no such inputs, so what other inputs might make that sscanf line fail? And is there a better way to write a sscanf line for this problem?

TIA.

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong
Noim wrote:Ming Man ,
Are you really getting WR or Run Time error. You are declaring line[3] but accessing with line[1] line[2] line[3] which is suppose to be line[0], line[1], line[2].
Well, it seems to me that the judge compiler sometimes wrongly states that a program gets WA, while the real bug is RTE.
If you are using Pascal, you'll see this problem quite frequently.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:
It all depends on how the complier and linker put the variables in memory. So, it's conceivable that they were allocated as so:

Code: Select all

``````+-----+---------+---------+---------+----+-----+
| ... | line[0] | line[1] | line[2] | li | ... |
+-----+---------+---------+---------+----+-----+``````
Thus, line[3] is valid in C/C++, since, you're just adding 3 to the "line" pointer, which potentially lands you in "li" and thus no runtime error occrus. The same might happen for line[-1] in this case, if there were variables in memory associated before "line" was.

I think Java arrays are a bit better than C/C++ arrays here in this regard, because they provide bounds checking (especially for newbies who don't understand pointer arithmetic much), so it's easier to debug when you have some minor error like this. (Then again, you could always use the STL vector class, and use the at() function to index stuff with bounds checking, but that's annoying and looks a bit funny =P)

Just trying to say that there's no way the Judge compiler can mark those as RTE instead of WA, 'cause that's just the way the C/C++ handling of arrays are.

Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

### Solved

I rewrote the code and finally solved the problem using a different approach.

Thanks.
:: HanWorks ::

smilejfu
New poster
Posts: 5
Joined: Fri Oct 08, 2004 2:29 pm
Contact:

### 576 Compile Error......T^T

I don't know what's the matter with my code....
I've used Dev-C++ to compile my code
but I got Compile Error...
can somebody tells me what happened??
thanks...

[code]
#include <stdio.h>
int main(void)
{
char ch[205];
int i,count,q,check;

while(gets(ch))
{
if(strcmpi(ch,"e/o/i")==0) break;
i=0; check=0;
count=0; q=1;
while(ch[i]!='/')
{
if(ch[i]=='a'||ch[i]=='e'||ch[i]=='i'||ch[i]=='o'||ch[i]=='u'||ch[i]=='y')
{
if(q)
count++;
q=0;
}
else
q=1;
i++;
}
if(count!=5) { printf("1"); check=1; }

count=0; q=1; i++;
while(ch[i]!='/')
{
if(ch[i]=='a'||ch[i]=='e'||ch[i]=='i'||ch[i]=='o'||ch[i]=='u'||ch[i]=='y')
{
if(q)
count++;
q=0;
}
else
q=1;
i++;
}
if(count!=7) { printf("2"); check=2; }

count=0; q=1; i++;
while(ch[i]!='\0')
{
if(ch[i]=='a'||ch[i]=='e'||ch[i]=='i'||ch[i]=='o'||ch[i]=='u'||ch[i]=='y')
{
if(q)
count++;
q=0;
}
else
q=1;
i++;
}
if(count!=5) { printf("3"); check=3; }

if (check==0) printf("Y");
printf("\n");

}
return 0;
}
[/code]

Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET
I think the strcmpi in your code is causing the problem. Note that strcmpi is valid neither in ANSI C nor in UNIX. To avoid CE (though I myself have recieved 80 CEs to date ), remember that judge uses UNIX system to compile your program.
You should never take more than you give in the circle of life.

smilejfu
New poster
Posts: 5
Joined: Fri Oct 08, 2004 2:29 pm
Contact:
thanks for your reply... ^^
I've found my mistake: if the syllables in three parts are 4/6/2,
I should print "1" instead of 123 !!
(thanks again~~ )[/c]

Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET
Nice to know that you're problem is solved.
You should never take more than you give in the circle of life.