576 WA PLEASE HELP
Posted: Thu Apr 06, 2006 7:17 am
HI EVERYBODY!
I HAVE TRIED MY LEVEL BEST AND MY PROGRAM GIVES THE CORRECT ANSWER FOR EVERY INPUT I CAN THINK OF. BUT I AM GETTING WA. PLEASE TELL ME WHAT'S WRONG WITH THE CODE OR SUPPLY SOME INPUT ON WHICH MY PROGRAM FAILS!! THANK YOU
# include <iostream>
# include <cstring>
using namespace std;
main ()
{
char syll[205];
while (cin.getline(syll,202)) // input each syll
{
if ( strcmp(syll,"e/o/i") == 0 ) // terminate program
break;
int line=1;
int vowel=0, syllcount=0, flag=0;
for (int i=0; i<=strlen(syll); i++) // scan through each char
{
// if / then next line or \n then endofSyll
if (syll == '/' || syll== '\0')
{ // if first or third syllibi
if (line == 1 || line == 3 )
{
if (syllcount!=5) // if count less then quit
{
flag=1; // set flag for printing
break;
}
else syllcount=0; // else start count again for
} // next syllabi
else if (line == 2)
{
if (syllcount!=7)
{
flag=1; // set flag for printing
break;
}
else syllcount=0;
}
line++;
}
// check for vowel
else if (syll=='a'|| syll=='e'|| syll=='i'
|| syll=='o'|| syll=='u'|| syll=='y')
{
if (vowel==0) // if last char wasnt vowel then inc
syllcount++;
vowel=1; // flag showing last char was vowel
}
else vowel=0; // flag showing last char wasnt vowel
}
if (flag==0)
cout<< 'Y' << endl;
else cout << line << endl;
}
return 0;
}
I HAVE TRIED MY LEVEL BEST AND MY PROGRAM GIVES THE CORRECT ANSWER FOR EVERY INPUT I CAN THINK OF. BUT I AM GETTING WA. PLEASE TELL ME WHAT'S WRONG WITH THE CODE OR SUPPLY SOME INPUT ON WHICH MY PROGRAM FAILS!! THANK YOU
# include <iostream>
# include <cstring>
using namespace std;
main ()
{
char syll[205];
while (cin.getline(syll,202)) // input each syll
{
if ( strcmp(syll,"e/o/i") == 0 ) // terminate program
break;
int line=1;
int vowel=0, syllcount=0, flag=0;
for (int i=0; i<=strlen(syll); i++) // scan through each char
{
// if / then next line or \n then endofSyll
if (syll == '/' || syll== '\0')
{ // if first or third syllibi
if (line == 1 || line == 3 )
{
if (syllcount!=5) // if count less then quit
{
flag=1; // set flag for printing
break;
}
else syllcount=0; // else start count again for
} // next syllabi
else if (line == 2)
{
if (syllcount!=7)
{
flag=1; // set flag for printing
break;
}
else syllcount=0;
}
line++;
}
// check for vowel
else if (syll=='a'|| syll=='e'|| syll=='i'
|| syll=='o'|| syll=='u'|| syll=='y')
{
if (vowel==0) // if last char wasnt vowel then inc
syllcount++;
vowel=1; // flag showing last char was vowel
}
else vowel=0; // flag showing last char wasnt vowel
}
if (flag==0)
cout<< 'Y' << endl;
else cout << line << endl;
}
return 0;
}