576 - Haiku Review
Moderator: Board moderators
576 - Haiku Review
It seems that I keep getting wrong answer, but I tested the test cases and it worked perfectly.
Any suggestions? Thanks.
Any suggestions? Thanks.
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
Answer
What do you mean by sequencing a,e,i,o,u,y?
Is the answer: 3,1,1 ??
Thanks.
Is the answer: 3,1,1 ??
Thanks.
Re: Answer
sequencing like this: aaaaiiiiuuueeeooooMing Han wrote:What do you mean by sequencing a,e,i,o,u,y?
Is the answer: 3,1,1 ??
Thanks.
but i think you've handled it correctly.
anyway, the answer should be Y,1,1

maybe you could tell me your algo?
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.
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.
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.
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....
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]

[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]
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.
[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.
Well, it seems to me that the judge compiler sometimes wrongly states that a program gets WA, while the real bug is RTE.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].

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
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
It all depends on how the complier and linker put the variables in memory. So, it's conceivable that they were allocated as so:
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.
Code: Select all
+-----+---------+---------+---------+----+-----+
| ... | line[0] | line[1] | line[2] | li | ... |
+-----+---------+---------+---------+----+-----+
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.
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]
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]
-
- 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.
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET