博客版权已保护:转载请注明出处,谢谢。

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;
}

 

posted on 2018-07-27 21:51  superhero11  阅读(125)  评论(0编辑  收藏  举报

导航