Where is the Marble? (algorithm)

Posted myxdashuaige

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Where is the Marble? (algorithm)相关的知识,希望对你有一定的参考价值。

链接:https://vjudge.net/contest/239797#problem/A
/*

*这道题其实可以不用vector,直接用数组也是一样可以AC的。但是题目没有指定n的范围,所以就决定开动态数组比较保险;

*学会使用freopen("in.txt","r",stdin);来输入题目的样例,这样子就会节省很多时间

*学会使用algorithm之下的find函数,还有sort函数,max等等;

*/

#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    int n,q,cnt = 1,te;
    vector<int> A;
    vector<int> :: iterator it;
    while(cin >> n >> q && n && q)
    {
        A.clear();
        cout << "CASE# " << cnt++ << ":" << endl;
        for(int i=0;i<n;i++) {cin >> te;A.push_back(te);}
        sort(A.begin(),A.end());
        for(int i=0;i<q;i++)
        {
            cin >> te;
            it = find(A.begin(),A.end(),te);
            if(it == A.end()) cout << te << " not found" << endl;
            else
            {
                for(int j=0;j<A.size();j++)
                if(A[j] == te) {cout << te << " found at " << j+1 << endl;break;}
            }
        }


    }

    return 0;
}

 


以上是关于Where is the Marble? (algorithm)的主要内容,如果未能解决你的问题,请参考以下文章

UVA - 10474 Where is the Marble?(排序)

UVA10474 Where is the Marble?排序

Where is the Marble?(sort+lower_bound使用)

Where is the Marble? (algorithm)

UVA 10474 Where is the Marble

排序与检索UVa10474Where is the Marble?