首页 > 代码库 > uva10474 - Where is the Marble?
uva10474 - Where is the Marble?
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 }
排序,然后匹配
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。