ACM Easy Tiae words





Problem Link: http://acm.epoka.edu.al:8888/en/problem-pid-c7b4?ps=1&smt=a&smpwid=0



#include <bits/stdc++.h>
using namespace std;

bool isVowel(char ch)
{

    return ( ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U');

}

bool comparegrade( const pair<string,float>& x, const pair<string, float>& y )
{

    if(x.second==y.second)
    {
        return x.first<y.first;
    }

    return (x.second>y.second); //descending

}


int main()
{

    int n,m,t,i,j,k,l,v,cnt=0;
    float tv;
    string s;
    vector<pair<string,float> >a;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        v=0;
        cin>>s;
        l=s.size();
        for(j=0;j<l;j++)
        {
            if(isVowel(s[j]))
            {
                v++;
            }
        }
        tv= ((float)v/(float)l)*100;
        //cout<<tv<<endl;

        a.push_back(make_pair(s,tv));

    }
    sort(a.begin(),a.end(),comparegrade);
    vector<pair<string,float> >::iterator p;

    for(p=a.begin();p!=a.end();p++)
    {
         if(cnt==m)
         {
             break;
         }
         cout<<p->first<<endl;
         cnt++;
    }


    return 0;


}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment