zcmu1339: Exam ranking

Title link: https://acm.zcmu.edu.cn/JudgeOnline/problem.php?id=1339

Topic

The acm competition system calculates the final penalty time, n people and m questions. Negative number -ai means failed and tried ai sending; positive number ai means time when passed. If there are brackets, there is a number bi in it, which means that we have failed bi times before and need to be added when calculating the penalty time ai+bi*s, s represents the unit penalty. Finally, 10 grids are left-aligned in descending order of the number of passes, 2 grids are right-aligned in ascending order of time penalty, and 4 grids are placed in ascending lexicographical order, and the output results are sorted.

Ideas

Simulation + sorting. See if it is negative or 0, and skip if it is. Then look at whether there are parentheses, add extra time penalty if there are, and finally sort. The important thing is that there are two spaces between the three numbers. Don't forget! ! !

ac code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
    int cnt, score;
    string name;
    bool operator < (const node &a) const{
        if(cnt != a.cnt) return cnt > a.cnt;
        else if(score != a.score) return score < a.score;
        return name < a.name;
    }
}a[105];
int main(){
    int m, s, n;
    string b;
    cin >> m >> s >> n;
    for(int i = 1; i <= n; i ++){
        a[i].cnt = 0, a[i].score = 0;
        cin >> a[i].name;
        for(int j = 1; j <= m; j ++){
            cin >> b;
            if(b[0] == '-' || b == "0") continue;
            a[i].cnt ++;
            int id = 0, l = b.length(), cc = 0, res = 0; // id表示左括号的位置,l表示字符串长度, res表示罚时,cc表示之前提交次数
            while(id < l && b[id] != '(') id ++;
            for(int k = 0; k < id; k ++){
                res = res * 10 + b[k] - '0';
            }
            a[i].score += res;
            if(id != l){
                for(int k = id + 1; k < l - 1; k ++){
                    cc = cc * 10 + b[k] - '0';
                }
                a[i].score += cc * s;
            }
        }
    }
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; i ++){
        int l = a[i].name.length();
        cout << a[i].name;
        for(int i = 0; i < 10 - l; i ++) cout << " ";
        printf(" %2d %4d\n", a[i].cnt, a[i].score); //前面有两个空格的,呜呜呜
    }
    return 0;
}

 

Guess you like

Origin blog.csdn.net/weixin_43911947/article/details/113330468