Task: | Robotti |
Sender: | SillyBilly |
Submission time: | 2024-11-01 13:44:34 +0200 |
Language: | C++ (C++17) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:58:48: error: cannot convert 'std::vector<int>::iterator' to 'const char*' 58 | coinloc.erase(std::remove(coinloc.begin(), coinloc.end(), robotPos), coinloc.end()); | ~~~~~~~~~~~~~^~ | | | std::vector<int>::iterator In file included from /usr/include/c++/11/cstdio:42, from /usr/include/c++/11/ext/string_conversions.h:43, from /usr/include/c++/11/bits/basic_string.h:6608, from /usr/include/c++/11/string:55, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from input/code.cpp...
Code
#include <iostream> #include <vector> #include <string> #include <cmath> int main() { int n; std::string rooms; std::cin >> n >> rooms; int robotPos = rooms.find('R'); std::vector<int> coinloc; for (int i = 0; i < n; ++i) { if (rooms[i] == '*') { coinloc.push_back(i); } } int steps = 0; int coins = 0; while (!coinloc.empty()) { int Left = -1; int Right = -1; for (int pos : coinloc) { if (pos < robotPos) { Left = pos; } else if (pos > robotPos && Right == -1) { Right = pos; break; } } if (Left == -1 && Right == -1) { break; } else if (Left == -1) { steps += std::abs(robotPos - Right); robotPos = Right; } else if (Right == -1) { steps += std::abs(robotPos - Left); robotPos = Left; } else { int distLeft = std::abs(robotPos - Left); int distRight = std::abs(robotPos - Right); if (distLeft < distRight) { steps += distLeft; robotPos = Left; } else if (distRight < distLeft) { steps += distRight; robotPos = Right; } else { break; } } coins++; coinloc.erase(std::remove(coinloc.begin(), coinloc.end(), robotPos), coinloc.end()); } std::cout<< steps<<" "<<coins<<std::endl; }