2013
12-23

# EXCEL排序

Excel可以对一组纪录按任意指定列排序。现请你编写程序实现类似功能。

3 1
000007 James 85
000010 Amy 90
000001 Zoe 60
4 2
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 98
4 3
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 90
0 0

Case 1:
000001 Zoe 60
000007 James 85
000010 Amy 90
Case 2:
000010 Amy 90
000002 James 98
000007 James 85
000001 Zoe 60
Case 3:
000001 Zoe 60
000007 James 85
000002 James 90
000010 Amy 90

http://acm.hdu.edu.cn/showproblem.php?pid=1862

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef struct _excel
{
char no[7];
char name[9];
int score;
}excel;

excel ex[100001];

int cmpno(const void *a, const void *b)
{
excel *fa = (excel*)a;
excel *fb = (excel*)b;
return strcmp(fa->no, fb->no) > 0 ? 1 : -1;
}

int cmpname(const void *a, const void *b)
{
excel *fa = (excel *)a;
excel *fb = (excel *)b;
if(strcmp(fa->name, fb->name)!=0)return strcmp(fa->name, fb->name) > 0 ? 1 : -1;
return strcmp(fa->no, fb->no) > 0 ? 1 : -1;
}

int cmpscore(const void *a, const void *b)
{
excel *fa = (excel *)a;
excel *fb = (excel *)b;
if(fa->score != fb->score)return fa->score - fb->score > 0 ? 1 : -1;
return strcmp(fa->no, fb->no) > 0 ? 1 : -1;
}

int main()
{
//    freopen("input.in", "r", stdin);
int n, i, hw;
int cas = 1;
while(scanf("%d%d", &n, &hw)&&n){
for(i = 0; i < n; i ++){
scanf("%s%s%d", ex[i].no, ex[i].name, &ex[i].score);
}
if(hw == 1){
qsort(ex, n, sizeof(ex[0]), cmpno);
}
else if(hw == 2){
qsort(ex, n, sizeof(ex[0]), cmpname);
}
else if(hw == 3){
qsort(ex, n, sizeof(ex[0]), cmpscore);
}

printf("Case %d:\n", cas ++);
for(i = 0; i < n; i ++){
printf("%s %s %d\n", ex[i].no, ex[i].name, ex[i].score);
}
}
return 0;
}

1. 不考虑最后将结果排序的话，快排的时间复杂度是O(N) ，而堆排的是O(N*logK),这样比较看，快排快

2. for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
dp = dp [j-1] + 1;
if(s1.charAt(i-1) == s3.charAt(i+j-1))
dp = dp[i-1] + 1;
if(s2.charAt(j-1) == s3.charAt(i+j-1))
dp = Math.max(dp [j - 1] + 1, dp );
}
}
这里的代码似乎有点问题？ dp(i)(j) = dp(i)(j-1) + 1;这个例子System.out.println(ils.isInterleave("aa","dbbca", "aadbbcb"));返回的应该是false