Task: | Robotti |
Sender: | onniK |
Submission time: | 2024-11-06 11:24:38 +0200 |
Language: | C++ (C++17) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:16:35: warning: comparison of integer expressions of different signedness: 'int' and 'const size_type' {aka 'const long unsigned int'} [-Wsign-compare] 16 | int left_distance = (left != string::npos) ? robot_position - left : n; | ~~~~~^~~~~~~~~~~~~~~ input/code.cpp:17:37: warning: comparison of integer expressions of different signedness: 'int' and 'const size_type' {aka 'const long unsigned int'} [-Wsign-compare] 17 | int right_distance = (right != string::npos) ? right - robot_position : n; | ~~~~~~^~~~~~~~~~~~~~~ input/code.cpp:19:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation] 19 | if (left_distance < right_distance) | ^~ input/code.cpp:21:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if' 21 | robot_position = left;...
Code
#include <iostream>#include <string>using namespace std;int main() {int n;string rooms;cin >> n >> rooms;int robot_position = rooms.find('R');int steps = 0, coins = 0;while (true) {int left = rooms.rfind('*', robot_position - 1);int right = rooms.find('*', robot_position + 1);int left_distance = (left != string::npos) ? robot_position - left : n;int right_distance = (right != string::npos) ? right - robot_position : n;if (left_distance < right_distance)steps += left_distance;robot_position = left;} else if (right_distance < left_distance) {steps += right_distance;robot_position = right;} else {break;}coins++;rooms[robot_position] = '.';}cout << steps << " " << coins << endl;return 0;}//6.11.2024 11:22 Onni Kolehmaienen// Syöte esimerkki://20//**.*......*.R*...*..//Tuloste://4 2