Sunday, 22 July 2012

UVa 576 - Haiku Review Solution

#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>

using namespace std;

#define INF (1<<29)
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define FILL(a,v) memset(a,v,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define LL long long
#define MX 100000
#define MOD 1000000007

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

main()
{
    string line;
    int cnt1,cnt2,cnt3,i;
    while(getline(cin,line))
    {
        if(line=="e/o/i")   break;

        cnt1=cnt2=cnt3=0;

        if(isVowel(line[0]))
        cnt1++;
        for(i=1;;i++)
        {
            if(line[i]=='/')    break;
            if(isVowel(line[i]) && !isVowel(line[i-1]))
            cnt1++;
        }

        if(isVowel(line[i+1]))
        cnt2++;
        for(i=i+2;;i++)
        {
            if(line[i]=='/')    break;
            if(isVowel(line[i]) && !isVowel(line[i-1]))
            cnt2++;
        }


        if(isVowel(line[i+1]))
        cnt3++;
        for(i=i+2;i<line.length();i++)
        {
            //if(line[i]=='/')    break;
            if(isVowel(line[i]) && !isVowel(line[i-1]))
            cnt3++;
        }

        //cout<<cnt1<<" "<<cnt2<<" "<<cnt3<<endl;
        if(cnt1!=5)
        cout<<"1";
        else if(cnt2!=7)
        cout<<"2";
        else if(cnt3!=5)
        cout<<"3";
        else
        cout<<"Y";
        cout<<endl;


    }
}

No comments:

Post a Comment