当前位置:编程学习 > C/C++ >>

(DS1.5.4)POJ 1581 A Contesting Decision(结构体排序)

 
/* 
 * POJ_1581.cpp 
 * 
 *  Created on: 2013年10月19日 
 *      Author: Administrator 
 */  
  
#include <iostream>  
#include <cstdio>  
#include <algorithm>  
  
using namespace std;  
  
struct Team {  
    char name[100];  
    int solveNum;  
    int totalTime;  
  
    bool operator<(const Team& n) const {  
        if (solveNum > n.solveNum) {  
            return true;  
        }  
  
        if (solveNum == n.solveNum && totalTime < n.totalTime) {  
            return true;  
        }  
  
        return false;  
    }  
} teams[4];  
  
int main() {  
    int n;  
    scanf("%d", &n);  
  
    int i, j;  
    for (i = 0; i < n; ++i) {  
        scanf("%s", teams[i].name);  
        teams[i].solveNum = 0;  
        teams[i].totalTime = 0;  
  
        for (j = 0; j < 4; ++j) {  
            int a, b;  
            scanf("%d %d", &a, &b);  
  
            if (b != 0) {  
                teams[i].solveNum += 1;  
                teams[i].totalTime += ((a - 1) * 20 + b);  
            }  
        }  
  
    }  
  
    sort(teams, teams + 4);  
  
    printf("%s %d %d\n", teams[0].name, teams[0].solveNum, teams[0].totalTime);  
  
    return 0;  
}  

 

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,