zoukankan      html  css  js  c++  java
  • HDU1862

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1862

    解题思路:结构体排序

    #include <bits/stdc++.h>
    using namespace std;
    struct student {
        int no;
        string name;
        int grade;
    }stu[100005];
    bool cmp1(student s1, student s2) {
        return s1.no < s2.no;
    }
    bool cmp2(student s1, student s2) {
        if (s1.name < s2.name) {
            return true;
        } else if (s1.name == s2.name) {
            return s1.no < s2.no; 
        }
        return false;
    }
    bool cmp3(student s1, student s2) {
        if (s1.grade < s2.grade) {
            return true;
        } else if (s1.grade == s2.grade) {
            return s1.no < s2.no; 
        }
        return false;
    }
    int main() {
        int n, c, cas = 1;
        while (cin >> n >> c, n) {
            for (int i = 0; i < n; i++) {
                cin >> stu[i].no >> stu[i].name >> stu[i].grade;
            }
            if (c == 1) {
                sort(stu, stu+n, cmp1);
            } else if (c == 2) {
                sort(stu, stu+n, cmp2);
            } else if (c == 3) {
                sort(stu, stu+n, cmp3);
            }
            printf("Case %d:
    ", cas++);
            for (int i = 0; i < n; i++) {
                printf("%06d %s %d
    ", stu[i].no, stu[i].name.c_str(), stu[i].grade);
                //.c_str()将string转换成char[] 
            }
        }
        return 0;
    } 
  • 相关阅读:
    4、2 核心组件
    promise
    Content-Type
    $routeProvider
    广告
    $apply() $digest()
    异常
    switch
    autoprefixer
    $resource
  • 原文地址:https://www.cnblogs.com/oeong/p/12108173.html
Copyright © 2011-2022 走看看