标签:std color str system tab swap 长方形 格式 log
1 8 1 1 1 1 1 1 1 1 2 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1
1 1 1 1 2 1 1 2 2 2 1 1 2 2 1
1 2 #include <iostream> 3 #include <vector> 4 #include <algorithm> 5 #include <cstdio> 6 using namespace std; 7 8 typedef struct retangle{ 9 int number; 10 int length; 11 int width; 12 }rectangle; 13 14 bool comp(rectangle a, rectangle b){ 15 if(a.number != b.number) 16 return a.number < b.number; 17 else if(a.length != b.length) 18 return a.length < b.length; 19 else 20 return a.width < b.width; 21 } 22 23 int main(){ 24 int test, i, n; 25 cin >> test; 26 vector<rectangle> v; 27 rectangle r; 28 while(test--){ 29 v.clear(); 30 cin >> n; 31 for(int j = 0; j < n; j++){ 32 cin >> r.number >> r.length >> r.width; 33 if(r.length < r.width) 34 swap(r.length, r.width); 35 v.push_back(r); 36 } 37 sort(v.begin(), v.end(), comp); 38 //cout << v[0].number << v[0].length << v[0].width << endl; 39 printf("%d %d %d\n", v[0].number, v[0].length, v[0].width); 40 for(i = 1; i < n; i++){ 41 if((v[i].number == v[i-1].number) && (v[i].length == v[i-1].length) 42 && (v[i].width == v[i-1].width)) 43 continue; 44 else 45 printf("%d %d %d\n", v[i].number, v[i].length, v[i].width); 46 //cout << v[i].number << v[i].length << v[i].width << endl; 47 } 48 } 49 //system("pause"); 50 return 0; 51 }
nyoj 8 一种排序(用vector,sort,不用set)
标签:std color str system tab swap 长方形 格式 log
原文地址:http://www.cnblogs.com/qinduanyinghua/p/6393176.html