sdnuoj1104 資料排序

來源:互聯網
上載者:User
1104.資料排序
Time Limit: 1000 MS    Memory Limit: 12288 KB
Total Submission(s): 45    Accepted Submission(s): 15
Description
ZZK和SYC不知從哪個老師那裡拿到了一堆實驗資料,需要排序後再交回去。
實驗資料的格式為:
樣本序號 觀測資料
要求按照觀測資料由小到大排列,當觀測資料相等時按照出現順序排列
Input
實驗資料,每行兩個不超過100000的整數,分別為樣本序號和觀測資料,直到EOF
保證不超過100000行
Output
排序後的實驗資料
Sample Input
4 25 44 33 42 95 66 103 510 410 85 47 61 43 108 78 75 43 44 46 5
Sample Output
4 24 35 43 410 45 41 45 43 44 43 56 55 67 68 78 710 82 96 103 10
Hint
http://www.cplusplus.com/reference/algorithm/
對結構體排序可能需要自訂比較方法或著重載運算子stable_sort穩定排序
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;struct node{int x; int y;}f[100005];bool comp(node a,node b){return a.y<b.y;}int main(){int i=0;while(scanf("%d%d",&f[i].x,&f[i].y)!=EOF)i++;stable_sort(f,f+i,comp);for(int j=0;j<i;j++)printf("%d %d\n",f[j].x,f[j].y);return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.