l_migrant 2021-10-31 10:00 采纳率: 83.3%
浏览 43
已结题

一道结构体排序的题目,挂oj上wa,代码有注释,可以看看吗?

img

Sample Input 1

3 5
2 29 1 wa
2 30 1 ac
2 50 2 ac
1 51 2 ac
3 60 2 ac
Sample Output 1

2 2 100
1 1 51
3 1 60

#include "cstdio"
#include "iostream"
#include "string"
#include "algorithm"
using namespace std;
struct node
{
    int idex;    //编号
    int solve;    //解决的题目
    int total;    //总共的时间
    int punish[11];    //题目【i】的罚时
    bool p[11];        //题目【i】有没有对过
};
node team[1005];
string res;
int n, m, num, t, pro;
bool cmp(node a, node b);

int main()
{
    scanf("%d%d", &n, &m);
    for(int i =1; i <= n; i++)
        team[i].idex = i;
    while(m)
    {
        scanf("%d%d%d", &num, &t, &pro);//队伍编号, 现在的时间, 尝试的题目
        cin >> res;                        //解题状态
        if(res == "ac" && !team[num].p[pro])
        {
            team[num].solve++;
            team[num].total += t + team[num].punish[pro] * 20;
            team[num].p[pro] = 1;
        }
        else
        {
            team[num].punish[pro]++;
        }        
        m--;
    }
    sort(team + 1, team + n + 1, cmp);
    for(int i = n; i > 0; i--)
        printf("%d %d %d\n", team[i].idex, team[i].solve, team[i].total);
    return 0;
}

bool cmp(node a, node b)
{
    if(a.solve > b.solve)
        return a.solve < b.solve;
    else if(a.solve == b.solve)
    {
        if(a.total == b.total)
            return a.idex > b.idex;
        return a.total < b.total;        
    }
    
}

  • 写回答

1条回答 默认 最新

  • l_migrant 2021-10-31 11:08
    关注

    img


    改成这样就过了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月8日
  • 已采纳回答 10月31日
  • 修改了问题 10月31日
  • 创建了问题 10月31日

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看