View Code of Problem 63

#include <iostream>
#include <string>
using namespace std;
string getName(string a){
	int j = 0;
	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] == ' ') {
			j = i;
			break;
		}
	}
	return a.substr(0,j);
}
string getHeight(string a) {
	int j = 0, court = 0;
	for (int i = 0; i < a.size(); i++)
	{
		if (court == 1 && a[i] == ' '&&a[i+1]!=' ') {
			return a.substr(j, i-j);
		}
		if (a[i] == ' '&&court==0) {
			j = i + 1;
			court++;
		}
	}
}
string getMoney(string a) {
	int j = 0, court = 0;
	for (int i = 0; i < a.size(); i++)
	{	
		if (a[i] == ' ' && court == 1) {
			j = i + 1;
			return a.substr(j, a.size()-j);
		}
		if (a[i]==' ') {
			court++;
		}
	}
}
int main() {
	int n;
	string data[1000];
	cin >> n;
	string a;
	getline(cin, a);//去掉空格
	for (int i = 0; i < n; i++)
	{
		getline(cin, a);
		data[i] = a;
	}
	string money, height;
	for (int i = 0; i < n; i++)
	{
		if (getName(data[i])=="Suxiao") {
			money = getMoney(data[i]);
			height = getHeight(data[i]);
			break;
		}
	}
	int m = 0, h = 0;
	for (int i = 0; i < n; i++)
	{
		string temp = getHeight(data[i]);
		if (temp < height)h++;
		temp = getMoney(data[i]);
		if (temp < money)m++;
	}
	if (h==m)cout << "EQ";
	else if (h >m)cout << "HEIGHT";
	else if (h<m)cout << "MONEY";
}

Double click to view unformatted code.


Back to problem 63