576 - Haiku Review
Moderator: Board moderators
I'm confused!
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;
}
#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;
}
instead of strcmpi, use strcmp (make sure you #include <string.h>)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), remember that judge uses UNIX system to compile your program.
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
..
-
- New poster
- Posts: 18
- Joined: Fri Jan 07, 2005 9:35 pm
- Location: Bangladesh
576 getting WA???
I have tried with more than 7 critical inputs, all showed the correct answers but still i am getting wrong answer!!!!!
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
-
- New poster
- Posts: 18
- Joined: Fri Jan 07, 2005 9:35 pm
- Location: Bangladesh
-
- New poster
- Posts: 18
- Joined: Fri Jan 07, 2005 9:35 pm
- Location: Bangladesh
I tested all the above test cases,and it's correctly.
But I still got WA.
Please help me.
Thanks a lot.
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.
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
Just change
to
While working with strings, never forget to allocate space for the Null terminating character. I think there's no other error in your program.
Code: Select all
stop[5]={"e/o/i"}
Code: Select all
stop[6]={"e/o/i"}
You should never take more than you give in the circle of life.
576- haiku review
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]
[codedeleted[/code]
Last edited by abhi on Fri Jan 13, 2006 4:36 am, edited 1 time in total.
-
- Learning poster
- Posts: 98
- Joined: Sat Jan 21, 2006 12:45 pm
- Location: Busan,Corea(Republic of)
576 Haiku Review WA!!!
#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?????????
#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?????????
Archaan
CAN YOU BEAT ME?
http://acm.uva.es/problemset/usersjudge.php?user=19788
AND,
http://acm.uva.es/problemset/submit.php
http://online-judge.uva.es/problemset/submit.php
SUBMIT AND GET AC!!!
CAN YOU BEAT ME?
http://acm.uva.es/problemset/usersjudge.php?user=19788
AND,
http://acm.uva.es/problemset/submit.php
http://online-judge.uva.es/problemset/submit.php
SUBMIT AND GET AC!!!
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact: