UVA-10474 大理石在哪儿(Where is the Marble?)

UVA-10474 大理石在哪儿(Where is the Marble?)


1. 问题描述

UVA-10474 大理石在哪儿(Where is the Marble?)

2. 代码实现
// #define LOCAL
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main() {
#ifdef LOCAL
  freopen("UVA-10474.in", "r", stdin);
  freopen("UVA-10474.out", "w", stdout);
#endif
  int mar_num, query_num, game_num = 0;
  while (scanf("%d %d", &mar_num, &query_num) == 2 && mar_num != 0) {
    int mar, query;
    vector<int> number;

    cout << "CASE# " << ++game_num << ":" << endl;
    for (int i = 0; i < mar_num; i++) {
      scanf("%d", &mar);
      number.push_back(mar);
    }
    sort(number.begin(), number.end());
    for (int i = 0; i < query_num; i++) {
      scanf("%d", &query);
      for (int i = 0; i < number.size(); i++) {
        if (number[i] == query) {
          cout << query << " found at " << i + 1 << endl;
          break;
        }
        if (i == number.size() - 1)
          cout << query << " not found" << endl;
      }
    }
  }
  return 0;
}
3. 验证案例

数据来源

  • 输入

    10 5 
    
    1 
    1 
    3 
    5 
    7 
    1 
    3 
    9 
    120 
    1 
    
    1 
    3 
    120 
    7 
    1234 
    
    10 12 
    
    1111 
    1111 
    1111 
    5 
    5 
    5 
    10 
    11 
    12 
    10 
    
    1111 
    5 
    10 
    11 
    12 
    1111 
    134 
    567 
    246 
    24 
    12 
    435 
    0 0
    
  • 输出

    CASE# 1:
    1 found at 1
    3 found at 5
    120 found at 10
    7 found at 8
    1234 not found
    CASE# 2:
    1111 found at 8
    5 found at 1
    10 found at 4
    11 found at 6
    12 found at 7
    1111 found at 8
    134 not found
    567 not found
    246 not found
    24 not found
    12 found at 7
    435 not found
    
    
  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值