uva 10474 - Where is the Marble?

简介: 点击打开链接 代码: //只要对输入的数据排序,然后查找即可(可用二分,更快)#include #include #include #include #include #include #include #inclu...

点击打开链接


代码:


//只要对输入的数据排序,然后查找即可(可用二分,更快)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <list>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 10010;

int n , q;
int arrN[MAXN];
int arrQ[MAXN];
int numQ[MAXN];

int main(){
    int cnt = 1;
    while(scanf("%d%d%*c" , &n , &q) &&q &&n){
       for(int i = 0 ; i < n ; i++)         
           scanf("%d" , &arrN[i]);
       sort(arrN , arrN+n);
       memset(arrQ , 0 ,sizeof(arrQ));
       for(int i = 0 ; i < q ; i++){
           scanf("%d" , &numQ[i]);
           for(int j = 0 ; j < n ;j++){
               if(numQ[i] == arrN[j]){
                   arrQ[numQ[i]] = j+1;
                   break;
               }
           }
       }
       printf("CASE# %d:\n" , cnt);
       for(int i = 0 ; i < q ; i++){
           if(arrQ[numQ[i]]){
               printf("%d found at %d\n" , numQ[i] , arrQ[numQ[i]]);
           }
           else
               printf("%d not found\n" , numQ[i]);  
       }
       ++cnt;
    }
    return 0;
}


目录
相关文章
UVa389 - Basically Speaking
UVa389 - Basically Speaking
37 0
UVA10474 大理石在哪儿 Where is the Marble?
UVA10474 大理石在哪儿 Where is the Marble?
hdu-1098 Ignatius's puzzle(费马小定理)
hdu-1098 Ignatius's puzzle(费马小定理)
158 0
hdu-1098 Ignatius's puzzle(费马小定理)
|
测试技术
HDU-1026,Ignatius and the Princess I(BFS+打印路径)
HDU-1026,Ignatius and the Princess I(BFS+打印路径)
HDU-1027,Ignatius and the Princess II
HDU-1027,Ignatius and the Princess II
LeetCode之Island Perimeter
LeetCode之Island Perimeter
127 0
LeetCode之Island Perimeter
|
Java C语言
HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)
HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)
141 0
|
存储 算法 测试技术
UVA - 10474 Where is the Marble
Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them.
1419 0