• hdu1862


    //开始把student stu[100000]放置在main()中导致栈溢出,所以必须放在全局位置,

    //可以调用数组的排序函数sort,包含头文件#include<algorithm>,在默认的情况下,数组sort函数进行升序排序

    //控制sort的第三个参数,传递函数指针进去,可以按照自己写的函数进行排序

    #include<iostream>
    #include<algorithm>
    using namespace std;
    class student{
    public:
    char number[7];
    char name[9];
    short mark;
    };
    student stu[100000];
    bool cmp1(student x, student y);
    bool cmp2(student x, student y);
    bool cmp3(student x, student y);
    int main()
    {
    int N, c, i, count = 0;
    while (cin >> N >> c&&N)
    {
    count++;
    for (i = 0; i < N; i++)
    cin >> stu[i].number >> stu[i].name >> stu[i].mark;;
    switch (c){
    case 1:sort(stu,stu+N,cmp1); break;
    case 2:sort(stu,stu+N,cmp2); break;
    case 3:sort(stu,stu+N,cmp3); break;
    }
    cout << "Case " << count << ":" << endl;
    for (i = 0; i < N; i++)
    cout << stu[i].number << ' ' << stu[i].name << ' ' << stu[i].mark << endl;
    }
    return 0;
    }
    bool cmp1(student x, student y)
    {
    if (strcmp(x.number, y.number) < 0)//学号递增排序
    return true;
    else
    return false;
    }
    bool cmp2(student x, student y)
    {
    if (strcmp(x.name, y.name)<0)
    return true;
    else if (strcmp(x.name, y.name) == 0)
    {
    if (strcmp(x.number, y.number) < 0)     //姓名非递减排序
    return true;
    else
    return false;
    }
    else
    return false;
    }
    bool cmp3(student x, student y)
    {
    if (x.mark < y.mark)
    return true;
    else if (x.mark == y.mark)
    {
    if (strcmp(x.number, y.number) < 0)        //分数非递减排序
    return true;
    else
    return false;
    }
    else
    return false;
    }

  • 相关阅读:
    SQL JOIN
    string.Empty, "" 和 null 三者的区别
    java JDBC
    java 自定义注解
    Spring Bean自动检测
    Spring Aware接口
    IObservable 接口
    CloseHandle()函数的使用
    [置顶] 记一次讲座与前辈的对话
    让用户关上门说话:覆盖全美6000个社区的邻居私密社交网站Nextdoor是如何壮大的?
  • 原文地址:https://www.cnblogs.com/td15980891505/p/4411600.html
Copyright © 2020-2023  润新知