uva-10152 - ShellSort
2012-07-31 20:17
260 查看
不知道为什么,一开始大脑转不过来了。。。。作了好久好久~~~~
额。。。。。
我 们对第二次输入的乌龟从0到n-1编号,然后对第一次输入的乌龟按照第二次的号码编号。
对与第一次乌龟顺序有变化的地放标记出来,然后把标记出来的这些点排序。
最后按照顺序输出就好了~~~
额。。。。。
我 们对第二次输入的乌龟从0到n-1编号,然后对第一次输入的乌龟按照第二次的号码编号。
对与第一次乌龟顺序有变化的地放标记出来,然后把标记出来的这些点排序。
最后按照顺序输出就好了~~~
#include<stdio.h> #include<string.h> #include<stdlib.h> int cmp ( const void *a , const void *b ) { return *(int *)a - *(int *)b; } int main() { int T,n,i,j,leapp,leap; char first[300][300]; char last[300][300]; int pop[300]; int sum[300],s[300]; scanf("%d",&T); while(T--) { scanf("%d%*c",&n); for(i=n-1;i>=0;i--) { gets(first[i]); } for(i=n-1;i>=0;i--) { gets(last[i]); sum[i]=i; } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(strcmp(first[i],last[j])==0) { s[i]=sum[j]; } } } leap=0; leapp=0; for(i=0;i<n;i++) { if(s[i]==leap) { leap++; } else { pop[leapp]=s[i]; leapp++; } } qsort(pop,leapp,sizeof(pop[0]),cmp); for(i=0;i<leapp;i++) { printf("%s\n",last[pop[i]]); } printf("\n"); } return 0; }
相关文章推荐
- UVa 10152 - ShellSort
- UVa 10152 - ShellSort
- UVA 10152 ShellSort
- UVa 10152 - ShellSort
- UVa 10152 - ShellSort
- UVA10152- ShellSort
- UVa 10152 ShellSort
- UVA - 10152 ShellSort
- UVA - 10152 ShellSort
- uva10152 ShellSort
- UVa 10152 - ShellSort
- uva10152-ShellSort
- UVA 10152 (暑期-线性表-E- ShellSort)
- Uva 10152 ShellSort
- uva10152 ShellSort
- uva 10152 shellsort
- UVA 10152 - ShellSort
- uva 10152 ShellSort
- Uva 10152 ShellSort
- uva 10152 ShellSort