寮は誰が一番高いですか.(20点)
10210 ワード
学校はバスケットボール選手を選抜し、寮ごとに最大4人がいる.寮のリストを出して、寮ごとに一番高い学生を見つけてください.身長height、体重weightなど、学生クラスStudentを定義します.
入力フォーマット:まず整数n(1<=n<=100000)を入力し、n人の同級生を表す.n行入力に続いて、各行フォーマットは:寮番号、name、height、weight.寮番号の区間は[09999999]で、nameはアルファベットで構成され、長さは16未満、height、weightは正の整数である.
出力フォーマット:寮番号によって小さいから大きいまで並べ替えて、各寮の身長が最も高い同級生の情報を出力します.テーマは寮ごとに身長が一番高い学生が一人しかいないことを保証します.
入力サンプル:7,000,000,000 Tom 175,120,000,000,000 Jack 180,130,000,000 Hale 160,140,000,000 Marry 160,120,120,120,120,000 Jerry 165,110,000,000,000,110,000,000 ETAF 183,145,1000001 Mickey 170,115出力サンプル:0,000 Tom 175,120,120,000,120,000,000 Jack 180,130,000,000,000,000,000,000,
私の問題:
注:タイトルはptaから
入力フォーマット:まず整数n(1<=n<=100000)を入力し、n人の同級生を表す.n行入力に続いて、各行フォーマットは:寮番号、name、height、weight.寮番号の区間は[09999999]で、nameはアルファベットで構成され、長さは16未満、height、weightは正の整数である.
出力フォーマット:寮番号によって小さいから大きいまで並べ替えて、各寮の身長が最も高い同級生の情報を出力します.テーマは寮ごとに身長が一番高い学生が一人しかいないことを保証します.
入力サンプル:7,000,000,000 Tom 175,120,000,000,000 Jack 180,130,000,000 Hale 160,140,000,000 Marry 160,120,120,120,120,000 Jerry 165,110,000,000,000,110,000,000 ETAF 183,145,1000001 Mickey 170,115出力サンプル:0,000 Tom 175,120,120,000,120,000,000 Jack 180,130,000,000,000,000,000,000,
私の問題:
#include
#include
#include
#include
using namespace std;
class Student
{
public:
Student() {}
public:
int dormitory;
string name;
int height;
int weight;
public:
};
int main(void)
{
int n;
cin >> n;
if (n < 1 || n>1000000)
exit(1);
Student* stus = new Student[n];// n Student
// map : 、 、
map<int, Student>stu_map; //int ,Student
for (int i = 0; i < n; i++)
{
cin >> stus[i].dormitory >> stus[i].name >> stus[i].height >> stus[i].weight; //
if (stu_map[stus[i].dormitory].height < stus[i].height)//
{
stu_map[stus[i].dormitory].name = stus[i].name;
stu_map[stus[i].dormitory].height = stus[i].height;
stu_map[stus[i].dormitory].weight = stus[i].weight;
}
}
for (map<int,Student>::iterator iter = stu_map.begin(); iter != stu_map.end(); iter++)
{
cout << setfill('0') << setw(6) << iter->first << " ";
cout<<iter->second.name << " " << iter->second.height << " " << iter->second.weight << endl;
}
delete[]stus;
return 0;
}
注:タイトルはptaから