CSES - Datatähti 2016 alku - Results
Submission details
Task:Kirjat
Sender:viderizer
Submission time:2015-09-30 17:59:42 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:73:36: error: no match for 'operator==' (operand types are 'std::vector<std::tuple<int, int, int> >::iterator {aka __gnu_cxx::__normal_iterator<std::tuple<int, int, int>*, std::vector<std::tuple<int, int, int> > >}' and 'std::vector<std::tuple<int, int, int> >::reverse_iterator {aka std::reverse_iterator<__gnu_cxx::__normal_iterator<std::tuple<int, int, int>*, std::vector<std::tuple<int, int, int> > > >}')
         if (get<2>(*it) == 0 && it == v.rbegin()) {
                                    ^
input/code.cpp:73:36: note: candidates are:
In file included from /usr/include/x86_64-linux-gnu/c++/4.9/bits/c++allocator.h:33:0,
                 from /usr/include/c++/4.9/bits/allocator.h:46,
                 from /usr/include/c++/4.9/string:41,
                 from /usr/include/c++/4.9/bits/locale_classes.h:40,
                 from /usr/include/c++/4.9/bits/ios_base.h:41,
                 from /usr/include/c++/4.9/ios:42,...

Code

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <tuple>
#include <set>
#include <algorithm>

using std::string;
using std::cin;
using std::cout;
using std::stoi;
using std::tuple;
using std::vector;
using std::stringstream;
using std::make_tuple;
using std::tuple_element;
using std::getline;
using std::get;
using std::find;

void debug(vector<int> v) {
    for (vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
        cout << *it << " ";
    }

    cout << "\n";
}

int main(int argc, char** argv) {
    // input
    int n;
    string n_s;
    string uolevi;
    string maija;

    getline(cin, n_s);
    n = stoi(n_s);
    getline(cin, uolevi);
    getline(cin, maija);

    // parsing input
    vector<tuple<int, int, int>> v;
    stringstream ss(uolevi);
    stringstream ss2(maija);
    string sub;
    string sub2;

    while (getline(ss, sub, ' ') && getline(ss2, sub2, ' ')) {
        v.push_back(make_tuple(stoi(sub), stoi(sub2), 0));
    }

    vector<int> unread;
    for (vector<tuple<int, int, int>>::reverse_iterator it = v.rbegin(); it != v.rend(); ++it) {
        if (find(unread.begin(), unread.end(), get<0>(*it)) == unread.end()) {
            unread.push_back(get<0>(*it));
        }
        if (find(unread.begin(), unread.end(), get<1>(*it)) == unread.end()) {
            unread.push_back(get<1>(*it));
        }
    }

    stringstream result_ss;

    for (vector<tuple<int, int, int>>::iterator it = v.begin(); it != v.end(); ++it) {
        for (vector<int>::iterator it2 = unread.begin(); it2 != unread.end(); ++it2) {
            if (*it2 != get<0>(*it) && *it2 != get<1>(*it)) {
                *it = make_tuple(get<0>(*it), get<1>(*it), *it2);
                unread.erase(it2);
                break;
            }
        }
        if (get<2>(*it) == 0 && it == v.rbegin()) {
            return 1;
        }
        //cout << "(" << get<0>(*it) << ", " << get<1>(*it) << ", " << get<2>(*it) << "), ";
        result_ss << get<2>(*it) << " ";
    }



    string result_s(result_ss.str());
    result_s.pop_back();

    cout << result_s << "\n";
    return 0;
}