UVA 10474 Where is the Marble?

水题

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 10010;
int pos[MAXN],a[MAXN];
int main(){
    int n,x,Q,cnt(0);
    while(~scanf("%d%d",&n,&Q) && n + Q){

        for(int i  = 1;i <= n;i ++) scanf("%d",a + i);
        sort(a+1,a+1+n);
        memset(pos,0,sizeof pos);
        for(int i = 1;i <= n;i ++) pos[a[i]] = pos[a[i]] ? pos[a[i]] : i;
        printf("CASE# %d:
",++cnt);
        for(int i = 0;i < Q;i ++){
            scanf("%d",&x);
            if(pos[x]) printf("%d found at %d
",x,pos[x]);
            else printf("%d not found
",x);
        }
    }
    return 0;
}


原文地址:https://www.cnblogs.com/anhuizhiye/p/3933178.html