Where is the Marble UVA - 10474

https://vjudge.net/problem/UVA-10474

本题证明了 uva的格式错误 不仅对换行敏感,对空格也敏感,并且发现关闭io流绑定确实能有效提速。

关闭前310ms,关闭后220ms。用到了之前很少用的distance()函数,用来算两个迭代器之间的距离,学习了。

#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
    cin.tie(0);
    cin.sync_with_stdio(false);
    int i, j, _cnt = 0; int temp;
    vector<int> marble;
    while (cin >> i >> j&& (i || j))
    {
        
        while (i--)
        {
            cin >> temp;
            marble.push_back(temp);
        }
        sort(marble.begin(), marble.end());
        cout << "CASE# " << ++_cnt << ":" << endl;
        while (j--)
        {
            cin >> temp;
            auto iter = find(marble.begin(), marble.end(), temp);
            if (iter != marble.end())
            {
                cout << temp << " found at " << distance(marble.begin(), iter) + 1 << endl;
            }
            else
            {
                cout << temp << " not found" << endl;
            }
        }
        marble.clear();
    }
    return 0;
}

 

posted @ 2019-04-11 22:48  超融合  阅读(124)  评论(0编辑  收藏  举报