思路
排序,比较排名位置
Description:
Suxiao是班里比较矮的一个小伙子,而这个家伙却又是最能吃的。所以每个月花费总是最多的。 他一向很自卑身高问题。他怕这个给他未来找女朋友带来极大麻烦。父母怕他吃的少故每个月也会给他比较多的钱的. 目前他想知道他在这个班级里到底是Height最具优势还是Money最具优势。这样可以帮助他寻找理想主义GF. 最具优势是什么意思呢?就是在班级他哪个方面排的比较靠前就是哪个方面最具优势咯. 看来最近世风日下攀比现象疑似非常严重?请大家谨慎行之!
Input:
第一行为一个整数N,表示这个班级里有N个男生 (1<=n<=1000) 以下N行,每行包含三个数据第一个名字(字符串) 第二是身高(整数) 第三是Money(整数),中间用空格分隔。 名字不包含空格,且不超过20个字符。
Output:
请找出Suxiao的最具优势方面?如果是高度最具优势则输出: HEIGHT 否则,如果是Money最近优势则输出:MONEY 如果具有相同优势,则输出:EQ
Sample Input:
4
Laocheng 175 800
Suxiao 168 850
Caimi 181 650
Langhua 168 900
Sample Output:
MONEY
#include <iostream>
#include "string"
#include "vector"
#include "algorithm"
using namespace std;
/**
* kkmd66
* @return
*/
int main() {
int n, m_Height, m_Money;
cin >> n;
//收集信息
vector<int> Height;
vector<int> Money;
for (int i = 0; i < n; ++i) {
string name;
int height, money;
cin >> name >> height >> money;
if (name == "Suxiao") {
m_Height = height;
m_Money = money;
}
Height.push_back(height);
Money.push_back(money);
}
//排序
sort(Height.begin(),Height.end());
sort(Money.begin(),Money.end());
//判断哪个优势
int locate_height,locate_money;
for (int i = 0; i < Height.size(); ++i) {
if (Height[i]==m_Height)
locate_height=i;
}
for (int i = 0; i < Money.size(); ++i) {
if (Money[i]==m_Money)
locate_money=i;
}
//输出
if (locate_money<locate_height)
cout<<"HEIGHT";
if (locate_money>locate_height)
cout<<"MONEY";
if (locate_height==locate_money)
cout<<"EQ";
return 0;
}