码迷,mamicode.com
首页 > 其他好文 > 详细

uva10474 - Where is the Marble?

时间:2014-06-07 03:49:29      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   a   

bubuko.com,布布扣
 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 }
View Code

排序,然后匹配

uva10474 - Where is the Marble?,布布扣,bubuko.com

uva10474 - Where is the Marble?

标签:c   style   class   blog   code   a   

原文地址:http://www.cnblogs.com/congluwen/p/3756100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!