Task: | Alitaulukot |
Sender: | Anniiiz |
Submission time: | 2020-09-30 15:01:43 +0300 |
Language: | C++ (C++11) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:15:7: error: conflicting declaration 'int s' int s = 0; ^ input/code.cpp:9:10: note: previous declaration as 'std::__cxx11::string s' string s; ^ input/code.cpp:20:12: error: no match for 'operator<' (operand types are 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' and 'std::vector<int>::size_type {aka long unsigned int}') while (s < vektori.size()) { ~~^~~~~~~~~~~~~~~~ In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0, from /usr/include/c++/7/bits/char_traits.h:39, from /usr/include/c++/7/ios:40, from /usr/include/c++/7/ostream:38, from /usr/include/c++/7/iostream:39, from input/code.cpp:2: /usr/include/c++/7/bits/stl_pair.h:454:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&) operator<(c...
Code
using namespace std; #include<iostream> #include<vector> #include <stdlib.h> int main() { int n, k; cin >> n >> k; string s; vector<int> vektori; int x; while (cin >> x) { vektori.push_back (x); } int s = 0; int a; int maara = 0; int pienin; int suurin; while (s < vektori.size()) { a = s; pienin = vektori[s] suurin = vektori[s] while (true) { if (a != vektori.size() - 1) { if (abs(suurin - vektori[a + 1]) <= k && abs(pienin - vektori[a + 1]) <= k { a ++; if (vektori[a] > suurin) { suurin = vektori[a]; } else if (vektori[a] < pienin) { pienin = vektori[a]; } } else { maara += (a - s + 1); s ++; if (vektori[s] > suurin) { suurin = vektori[s]; } else if (vektori[s] < pienin) { pienin = vektori[s]; } break; } } else { maara += a-s+1; s ++; if (vektori[s] > suurin) { suurin = vektori[s]; } else if (vektori[s] < pienin) { pienin = int(taulukko[s]) } break; } } } maara++; print(maara) }