Task: | Järjestys |
Sender: | peltola |
Submission time: | 2016-10-16 23:09:06 +0300 |
Language: | C++ |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:47:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if(j >= a.size()) { ^ input/code.cpp:91:11: error: cannot bind 'std::ostream {aka std::basic_ostream<char>}' lvalue to 'std::basic_ostream<char>&&' cout << op << " "; ^ In file included from /usr/include/c++/4.8/istream:39:0, from /usr/include/c++/4.8/sstream:38, from /usr/include/c++/4.8/complex:45, from /usr/include/c++/4.8/ccomplex:38, from /usr/include/x86_64-linux-gnu/c++/4.8/bits/stdc++.h:52, from input/code.cpp:7: /usr/include/c++/4.8/ostream:602:5: error: initializing argument 1 of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = std::vector<int>]' operator<<(basic_ostream<_CharT, _Traits>&...
Code
//#include <iostream> //#include <string> //#include <algorithm> //#include <vector> #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; // string op; // op = ""; int h; h = 0; int x[n]; vector<int> a; vector<int> op; for(int i = 0; i < n; i++) { int o; cin >> o; a.push_back(o); x[o - 1] = i; } for(int i = n; i > 1; i--) { for(int j = x[i - 1]; j >= 0; j--) { // j = min(j, a.size() - 1); if(j >= a.size()) { j = a.size(); } if(a[j] == i && j != (i - 1)) { if(j + 1 > 1) { op.push_back(j + 1); h++; } if(i > 1) { op.push_back(i); h++; } if(i - 1 > 1) { op.push_back(i - 1); h++; } if(j > 1) { op.push_back(j); h++; } a.erase(a.begin() + j); break; } } } cout << h; cout << "\n"; // for(int i = 0; i < op.size(); i++) { // cout << op[i]; // cout << " "; // } for(int i : op) cout << op << " "; cout << "\n"; return 0; }