zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    python 学习分享-进程
    python 学习分享-实战篇类 Fabric 主机管理程序开发
    python 学习分享-线程
    python 学习分享-paramiko模块
    linux ubuntu开启sshd
    python 学习分享-实战篇高级的ftp
    python 学习分享-socketserver
    python 学习分享-socket编程
    Java学习笔记--Java开发坏境搭建
    C# 泛型
  • 原文地址:https://www.cnblogs.com/td15980891505/p/4411600.html
Copyright © 2011-2022 走看看