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);
    	}
    
    
    }
    
  • 相关阅读:
    一个简单的空间配置器
    【转】c++中placement new操作符
    类的operator new与operator delete的重载【转】
    STL中常用的c++语法
    java编程思想-多态
    java编程思想-复用类(2)
    java编程思想-复用类
    import与require的区别
    gulp插件
    gulp-gulpfile.js语法说明
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812081.html
Copyright © 2011-2022 走看看