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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

1028.List Sorting (25)

2019-11-14 08:58:27
字體:
供稿:網(wǎng)友

1028.List Sorting (25)

pat-al-1028

2017-02-05

有測試點(diǎn)運(yùn)行超時(shí)但覺得沒什么問題的時(shí)候可以嘗試把cin和cout換成scanf和PRintfchar字符串?dāng)?shù)組比較必須用strcmp函數(shù),而不能像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;//因?yàn)椴荒苡胹tring類型,只能用char字符數(shù)組,所以只能用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);//不能用下面注釋掉的那行,會(huì)運(yùn)行超時(shí) //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-


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 苏尼特左旗| 宜春市| 山西省| 茶陵县| 临邑县| 宁乡县| 大足县| 梅河口市| 永和县| 和政县| 肇庆市| 包头市| 无棣县| 马尔康县| 兴国县| 若尔盖县| 平昌县| 徐汇区| 福建省| 南阳市| 光泽县| 赣州市| 宿州市| 潞城市| 弥渡县| 南充市| 建平县| 宜良县| 南京市| 化德县| 石林| 修水县| 陇南市| 苍山县| 麻栗坡县| 元朗区| 绥江县| 星子县| 塔城市| 南部县| 深泽县|