一种排序
Time Limit:1000MS Memory Limit:65536K
Total Submit:33 Accepted:24
Description
现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复;还知道这个长方形的宽和长,编号、长、宽都是整数;现在要求按照一下方式排序(默认排序规则都是从小到大);
1.按照编号从小到大排序
2.对于编号相等的长方形,按照长方形的长排序;
3.如果编号和长都相同,按照长方形的宽排序;
4.如果编号、长、宽都相同,就只保留一个长方形用于排序,删除多余的长方形;最后排好序按照指定格式显示所有的长方形;
Input
第一行有一个整数 0每一组第一行有一个整数 0接下来的m行,每一行有三个数 ,第一个数表示长方形的编号,
第二个和第三个数值大的表示长,数值小的表示宽,相等
说明这是一个正方形(数据约定长宽与编号都小于10000);
Output
顺序输出每组数据的所有符合条件的长方形的 编号 长 宽
Sample Input
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
Sample Output
1 1 1
1 2 1
1 2 2
2 1 1
2 2 1
Source
nyist
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AK093 {
class Program {
struct Rectangle {
public int len , wid , bian;
}
public class MyComparer : IComparer<Rectangle> {
int IComparer<Rectangle>.Compare(Rectangle x , Rectangle y) {
if (x.bian == y.bian) {
if (x.len == y.len)
return x.wid < y.wid ? -1 : 1;
return x.len < y.len ? -1 : 1;
}
return x.bian < y.bian ? -1 : 1;
}
}
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
while (n-- > 0) {
int m = int.Parse(Console.ReadLine());
Rectangle[] a = new Rectangle[m + 5];
for (int i = 0 ; i < m ; i++) {
string[] te = Console.ReadLine().Split();
a[i].bian = int.Parse(te[0]);
a[i].len = Math.Max(int.Parse(te[1]) , int.Parse(te[2]));
a[i].wid = Math.Min(int.Parse(te[1]) , int.Parse(te[2]));
}
Array.Sort(a , 0 , m , new MyComparer());
Console.WriteLine(a[0].bian + " " + a[0].len + " " + a[0].wid);
for (int i = 1 ; i < m ; i++) {
if (a[i].len == a[i - 1].len && a[i].wid == a[i - 1].wid && a[i].bian == a[i - 1].bian)
continue;
Console.WriteLine(a[i].bian + " " + a[i].len + " " + a[i].wid);
}
}
}
}
}