zoukankan      html  css  js  c++  java
  • A1028 List Sorting [排序]

    在这里插入图片描述
    ——————————————————————————————————————————————————
    考察

    1. 还是不要int的格式化输出 要不用字符串存id。
    2. 最后一组cin cout太慢了会超时,考这个点也是无语
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    struct student
    {
    	char id[15];
    	char name[15];
    	int score;
    }stu[100001];
    bool cmp1(student a, student b)
    {
    	return strcmp(a.id, b.id) < 0;
    }
    bool cmp2(student a, student b)
    {
    	if (strcmp(a.name, b.name) != 0)
    		return strcmp(a.name, b.name) < 0;
    	else
    		return strcmp(a.id, b.id) < 0;
    }
    bool cmp3(student a, student b)
    {
    	if (a.score != b.score)
    		return a.score < b.score;
    	else
    		return strcmp(a.id, b.id) < 0;
    }
    int main()
    {
    	int n, m;
    	cin >> n >> m;
    	for (int i = 0; i < n; i++)
    	{
    		cin>>stu[i].id >> stu[i].name >> stu[i].score;
    	}
    	if (m == 1)sort(stu, stu + n, cmp1);
    	else if (m == 2) sort(stu, stu + n, cmp2);
    	else if (m == 3)sort(stu, stu + n, cmp3);
    	for (int i = 0; i < n; i++)
    	{
    		printf("%s %s %d
    ", stu[i].id, stu[i].name, stu[i].score);
    	}
    
    
    }
    
  • 相关阅读:
    符号运算·
    笔记1
    Linux
    三数比较
    JavaScript变量,作用域和内存
    在HTML中使用JavaScript
    JavaScript基本概念
    JavaScript简介
    上机考试反思与总结
    计算机科学与技术学习方法
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812081.html
Copyright © 2011-2022 走看看