NYOJ595 乱七八糟

原题链接


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int a[100], b[101];
int cmp(const void *a, const void *b){
	return *(int *)b - *(int *)a;
}

int main(){
	int n, m, i, count, t, j;
	while(scanf("%d%d", &n, &m) == 2){
		if(n == 0 || m == 0) continue;
		for(i = 0; i != n; ++i)
			scanf("%d", &a[i]);
		qsort(a, n, sizeof(int), cmp);
		for(i = 0, count = 0; i != n; ++i, count = 0){
			for(j = i; j != n; ++j)
				if(a[i] == a[j])
					++count;
				else break;				
			b[i + 1] = count;
			i = j - 1;
		}
		while(m-- && scanf("%d", &t))
			printf("%d\n", b[t]);
		memset(b, 0, sizeof(b));
	}
	return 0;
}


posted on 2014-03-01 15:04  长木Qiu  阅读(137)  评论(0编辑  收藏  举报