1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 const int Max = 100000; 5 int num[Max]; 6 int find_[Max]; 7 bool found[Max]; 8 int pos[Max] = { 9 0 10 }; 11 int main() 12 { 13 int N, Q;int cas = 1; 14 for(int i = 0; i < Max;i++) 15 found[i] = false; 16 while(cin >> N >> Q, N || Q ) 17 { 18 for(int i = 0 ; i < N ;i++) 19 cin >> num[i]; 20 sort(num, num + N ); 21 for(int i = 0 ; i < Q; i++) 22 cin >> find_[i]; 23 int j; 24 for(int i = 0; i < Q; i++) 25 { 26 for(j = 0; j < N ;j++) 27 { 28 if(find_[i] == num[j]) 29 { 30 pos[i] = j + 1; 31 found[i] = true; 32 break; 33 } 34 } 35 } 36 cout << "CASE# " << cas++<<":\n"; 37 for(int i = 0 ; i < Q; i++) 38 { 39 if(found[i]) 40 { 41 cout << find_[i] << " found at " << pos[i] << endl; 42 } 43 else 44 { 45 cout << find_[i] << " not found\n"; 46 } 47 } 48 for(int i = 0 ; i < Max; i++) 49 found[i] = false; 50 } 51 return 0; 52 }
排序,然后匹配
uva10474 - Where is the Marble?,布布扣,bubuko.com
uva10474 - Where is the Marble?
原文地址:http://www.cnblogs.com/congluwen/p/3756100.html