题解:P5744 【深基7.习9】培训

· · 题解

题解

题目大意

给定 N 个人的名字、年龄、去年 NOIP 分数,设他们每个人今年的分数都会比去年提高 20\%,求他们今年的 NOIP 成绩。

思路

直接模拟,名字不变,年龄需要 +1,分数最高上限为 600,所以我们直接输出 \min(600, \lfloor score \times 1.2 \rfloor) 就行了。

注意:score 必须为 double 类型,输出的时候直接输出 min(600, int(score * 1.2)) 就是最终答案。

AC 代码

#include <bits/stdc++.h>
using namespace std;
#define in cin
#define out cout

signed main() {
    int t;
    in >> t;
    while (t--) {
        string s; //名字
        int year; //年龄
        double score; //分数
        in >> s >> year >> score;
        out << s << ' ' << ++year << ' ' << min(600, int(score * 1.2)) << '\n'; //如上所述
    }
    return 0;
}