n = gets.chomp.to_i
Student = Struct.new(:name, :num, :score)
maxstd = Student.new("","",0)
minstd = Student.new("","",101)
std = Student.new
(0...n).each { |i|
line = ""
line = gets.chomp.split
std = Student.new(line[0],line[1],line[2].to_i)
# std.name = line[0]
# std.num = line[1]
# std.score = line[2].to_i
if (std.score < minstd.score)
minstd = std
end
if (std.score > maxstd.score)
maxstd = std
end
}
puts (maxstd.name+ " " +maxstd.num)
puts (minstd.name+ " " +minstd.num)
C++:
#include <iostream>
#include <string>
using namespace std;
struct Student{
string name;
string num;
int score;
};
int main(){
int n;
cin >> n;
Student maxstd,minstd,std;
maxstd.score = -1;
minstd.score = 101;
while(n--){
cin >> std.name >> std.num >> std.score;
if (std.score > maxstd.score)
maxstd = std;
if (std.score < minstd.score)
minstd = std;
}
cout << maxstd.name << " " << maxstd.num << endl;
cout << minstd.name << " " << minstd.num << endl;
return 0;
}
Python:
n = int(input())
std_info = []
for i in range(3):
std = input()
std_info.append(std.split(' '))
res = sorted(std_info,key=lambda x:int(x[2]),reverse=True)
print(res[0][0] + ' ' + res[0][1])
print(res[-1][0]+ ' ' + res[-1][1],end='')
1004 成绩排名 (20分)
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...