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

yellow
New poster
Posts: 9
Joined: Tue Oct 26, 2004 6:26 am

I'm confused!

Post by yellow »

Everything is okie on my VC++, but I get the compile error everytime i submit the code:
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{

char line[200];
int numSyl[]={5,7,5}; //array of correct number of syllables (5/7/5)
cin.getline(line,'/n');

while (strcmpi(line,"e/o/i")) //check for end of file
{
int j=0;
int i=0;
bool allCorrect = true;
//check if the prvious character is a syllable
while(j<3)
{
int count=0;
bool flag=false;
//count number of syllables in each sentence
while(line!='/'&&line!=NULL)
{
if(line=='a'||line=='e'||line=='i'||line=='o'||line=='u'||line=='y')
{
if(flag==false)
{
count++;
flag=true;
}

}
else
flag=false;

i++;
}
i++;
if (count!=numSyl[j])
{
allCorrect = false;
cout<<(j+1);
break; //break the loop if one of the sentence has wrong number of syllables
}
j++;
}
if (allCorrect)
cout<<'Y';
cout<<endl;
cin.getline(line,'/n');
}

return 0;
}
wirjawan
New poster
Posts: 16
Joined: Fri Oct 01, 2004 10:48 pm
Location: Indonesia

Post by wirjawan »

Mohammad Mahmudur Rahman wrote: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 :wink:), remember that judge uses UNIX system to compile your program.
instead of strcmpi, use strcmp (make sure you #include <string.h>)

you might also want to fix the warnings below =)
[cpp]
cin.getline(line,'/n');
[/cpp]
to:
[cpp]
cin.getline(line,200,'\n'); /* 200 is the size of the buffer */
[/cpp]

and also
[cpp]
while(line!='/'&&line!=NULL)
[/cpp]
to:
[cpp]
while(line!='/'&&line!='\0')
[/cpp]

hope this helps
..
yellow
New poster
Posts: 9
Joined: Tue Oct 26, 2004 6:26 am

Post by yellow »

Greats!!! You really help me out, thanks a lot!
Fuad Hassan_IIUC(DC)
New poster
Posts: 18
Joined: Fri Jan 07, 2005 9:35 pm
Location: Bangladesh

576 getting WA???

Post by Fuad Hassan_IIUC(DC) »

I have tried with more than 7 critical inputs, all showed the correct answers but still i am getting wrong answer!!!!! :o plz help me out of this problem.
Last edited by Fuad Hassan_IIUC(DC) on Wed Feb 02, 2005 7:52 pm, edited 1 time in total.
fuad
Fuad Hassan_IIUC(DC)
New poster
Posts: 18
Joined: Fri Jan 07, 2005 9:35 pm
Location: Bangladesh

Post by Fuad Hassan_IIUC(DC) »

plz help me :o
fuad
Fuad Hassan_IIUC(DC)
New poster
Posts: 18
Joined: Fri Jan 07, 2005 9:35 pm
Location: Bangladesh

Post by Fuad Hassan_IIUC(DC) »

I got AC thank you :D
fuad
liang1425
New poster
Posts: 5
Joined: Thu May 26, 2005 8:20 am

Post by liang1425 »

I tested all the above test cases,and it's correctly.
But I still got WA.
Please help me.
Thanks a lot.

Code: Select all

cut
Last edited by liang1425 on Tue Jun 07, 2005 3:24 pm, edited 1 time in total.
Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Post by Mohammad Mahmudur Rahman »

Just change

Code: Select all

stop[5]={"e/o/i"}
to

Code: Select all

stop[6]={"e/o/i"}
While working with strings, never forget to allocate space for the Null terminating character. I think there's no other error in your program.
You should never take more than you give in the circle of life.
liang1425
New poster
Posts: 5
Joined: Thu May 26, 2005 8:20 am

Post by liang1425 »

Thank you :D
abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

576- haiku review

Post by abhi »

here is my code. it got AC in 0.002 sec. but there are soooo many users with 0.000. plz tell me where i can optimize the code. i am still a beginner .....i want to get AC in 0.000

[codedeleted[/code]
Last edited by abhi on Fri Jan 13, 2006 4:36 am, edited 1 time in total.
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

My friend, you are posting an accepted solution!
0.000 and 0.002 isn't of much difference. If you are lucky then you'll get 0.000 after submitting 2/3 times, if not earlier.
abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

Post by abhi »

i know that its not too much of a difference .......but still i would like to know y i got AC in 0.002 whereas many got AC in 0.000 in only their 1st attempt ????? y is it that i should submit 2 or 3 times whereas they get it AC on 0.000 in their 1st attempt only ???? :(
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

For those which you get runtime of 0.000 will mostly get in your first attempt. But sometimes it happens that you get it 0.002 and another attempt you get it in 0.000.
tmdrbs6584
Learning poster
Posts: 98
Joined: Sat Jan 21, 2006 12:45 pm
Location: Busan,Corea(Republic of)

576 Haiku Review WA!!!

Post by tmdrbs6584 »

#include<iostream.h>
#include<string.h>
char a[201];
int main(){
int z,x;
while(cin.getline(a,201)){
int len=strlen(a),i;
if(len==5 && a[0]=='e' && a[1]=='/' && a[2]=='o' && a[3]=='/' && a[4]=='i') break;
int cnt1=0,cnt2=0,cnt3=0;
for(i=0;i<len;i++){
if(a=='/') z=i;
}
for(i=0;i<len;i++){
if(i==z) continue;
if(a=='/') x=i;
}
for(i=0;i<x;i++){
if(a=='a' || a=='e' || a=='i' || a=='o' || a=='u' || a=='y') cnt1++;
}
if(cnt1==5){
for(i=x+1;i<z;i++){
if(a=='a' || a=='e' || a[i]=='i' || a[i]=='o' || a[i]=='u' || a[i]=='y') cnt2++;
}
if(cnt2==7){
for(i=z;i<len;i++){
if(a[i]=='a' || a[i]=='e' || a[i]=='i' || a[i]=='o' || a[i]=='u' || a[i]=='y') cnt3++;
}
if(cnt3==5) cout << "Y" << endl;
else cout << 3 << endl;
}
else cout << 2 << endl;
}
else cout << 1 << endl;
}
return 0;
}
WHY WA?????????
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

your algorithm is not right

think about some word like

Code: Select all

aaa
bbb
Post Reply

Return to “Volume 5 (500-599)”