Problem
https://uva.onlinejudge.org/external/104/10474.pdf
Solution
#include<iostream>
#define MAX_NUM 10005 // 最大數字為10000
using namespace std;
int main()
{
int N,Q,case_num = 0;
//若N和Q為0結束
while((cin >> N >> Q) && N && Q)
{
//用陣列計數所有的數字個數
int count[MAX_NUM] = {0};
for(int i = 0 ; i < N ; i++)
{
int temp;
cin >> temp;
count[temp]++;
}
cout << "CASE# " << ++case_num << ":" << endl;
for(int i = 0 ; i < Q ; i++)
{
int ask_num;
cin >> ask_num;
int ans = 0;
//如果數字個數為0個則為not found
if(count[ask_num] == 0)
cout << ask_num << " not found" << endl;
else
{
//計數到前一個數字的總數
for(int j = 0 ; j != ask_num ; j++)
ans += count[j];
//下一個數字的第一個所以要加1
ans++;
cout << ask_num << " found at " << ans << endl;
}
}//end of for i
}//end of while
return 0;
}