本文共 1201 字,大约阅读时间需要 4 分钟。
题意:看代码
#include #include #include #include #include #include #include #include #include #include using namespace std;#define N 12000int a[N];int n, m;void sort(){ for(int i = 0; i < n; i++) for(int j = 1; j < n - i; j++) if(a[j - 1] > a[j]) { int t = a[j - 1]; a[j - 1] = a[j]; a[j] = t; }}int find(int k){ for(int i = 0; i < n; i++) { if(!(a[i] ^ k)) return i; } return -1;}int sort(const void* a, const void* b){ int *pa = (int*) a; int *pb = (int*) b; return (*pa) - (*pb);}int main(const int argc, char** argv){ //freopen("d:\\1.txt", "r", stdin); int t = 1; while (scanf("%d %d", &n, &m)) { if(m == n && n == 0) return 0; printf("CASE# %d:\n", t); t++; for(int i = 0; i < n; i++) scanf("%d", a + i); qsort(a, n, sizeof(int), sort); int k = 0; for(int i = 0; i < m; i++) { scanf("%d", &k); int kk = -1; if((-1 ^ (kk = find(k)))) { printf("%d found at %d\n", k, kk + 1); } else { printf("%d not found\n", k); } } }}
冒泡排序。。。时间1.2s
快排。。。时间 390ms
转载于:https://www.cnblogs.com/shuiyonglewodezzzzz/p/7835441.html