Uva--10474 (排序)
2014-06-03 00:01:44
题意&思路:随便敲个排序上去即可,这里手敲复习了一下快排。
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <functional> using namespace std; const int maxn = 10000; void quick_sort(int *s,int l,int r){ if(l < r){ int i = l,j = r,x = s[l]; while(i < j){ while(i < j && s[j] > x) --j; if(i < j) s[i++] = s[j]; while(i < j && s[i] <= x) ++i; if(i < j) s[j--] = s[i]; } s[i] = x; quick_sort(s,i + 1,r); quick_sort(s,l,i - 1); } } int main(){ int Case = 0; int n,q,m,v[maxn + 5],pos[maxn + 5]; while(scanf("%d %d",&n,&q) == 2){ memset(pos,0,sizeof(pos)); if(n == 0 && q == 0) break; for(int i = 0; i < n; ++i){ scanf("%d",&v[i]); } quick_sort(v,0,n - 1); //sort(v,v + n); int mark = -1; for(int i = 0; i < n; ++i){ if(v[i] != mark){ mark = v[i]; pos[v[i]] = i + 1; } } printf("CASE# %d:\n",++Case); while(q--){ scanf("%d",&m); if(pos[m]){ printf("%d found at %d\n",m,pos[m]); } else{ printf("%d not found\n",m); } } } return 0; }