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;
    }

  • 相关阅读:
    解决png图像透明问题
    常用的CSS命名规则
    站点跨域登录
    SVN服务器配置
    开源方便的PHP & Flash图表:Open Flash Chart
    php+mysql无限级分类(非递归)
    地址栏显示图标 Shortcut Icon
    mysql set类型和enum类型
    通过 WebDAV 协议访问版本库(http://)
    年薪第一的数据库工程师是怎样炼成的
  • 原文地址:https://www.cnblogs.com/td15980891505/p/4411600.html
Copyright © 2011-2022 走看看