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;
}
0 comments:
Post a Comment