国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1028.List Sorting (25)

2019-11-14 09:51:11
字體:
來源:轉載
供稿:網友

1028.List Sorting (25)

pat-al-1028

2017-02-05

有測試點運行超時但覺得沒什么問題的時候可以嘗試把cin和cout換成scanf和PRintfchar字符串數組比較必須用strcmp函數,而不能像string類型可以直接比較坑見注釋/** * pat-al-1028 * 2017-02-05 * Cpp version * Author: fengLian_s */#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>//坑:strcmp在<string.h>中,不是在<string>中#define MAX 100001using namespace std;int c;struct STU{ int id; char name[10]; int score;}stu[MAX];bool cmp(STU a, STU b){ if(c == 1) return a.id < b.id; else if(c == 2) { if(strcmp(a.name, b.name) != 0) return strcmp(a.name, b.name) < 0;//因為不能用string類型,只能用char字符數組,所以只能用strcmp來比較 else return a.id < b.id; } else { if(a.score != b.score) return a.score < b.score; else return a.id < b.id; }}int main(){ int n; cin >> n >> c; for(int i = 0;i < n;i++) { scanf("%d%s%d", &stu[i].id, stu[i].name, &stu[i].score);//不能用下面注釋掉的那行,會運行超時 //cin >> stu[i].id >> stu[i].name >> stu[i].score; //cout << stu[i].id << stu[i].name << stu[i].score << endl; } sort(stu, stu+n, cmp); for(int i = 0;i < n;i++) { printf("%06d %s %d/n", stu[i].id, stu[i].name, stu[i].score); } return 0;}

-FIN-


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 禹州市| 五河县| 禄劝| 三穗县| 边坝县| 威远县| 乐都县| 浮梁县| 图木舒克市| 呼和浩特市| 克拉玛依市| 龙岩市| 怀宁县| 上虞市| 泗洪县| 蛟河市| 缙云县| 正宁县| 罗江县| 绥滨县| 当涂县| 镇坪县| 阜宁县| 芒康县| 拜泉县| 同江市| 兴山县| 隆昌县| 无为县| 德州市| 三门县| 普洱| 丘北县| 祁连县| 平和县| 黔西县| 永清县| 大安市| 平山县| 容城县| 卢龙县|