Task: | Robotti |
Sender: | osmukka |
Submission time: | 2024-11-04 17:34:03 +0200 |
Language: | C++ (C++17) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:15:19: error: invalid conversion from 'void*' to 'char*' [-fpermissive] 15 | rooms = malloc(amount); | ~~~~~~^~~~~~~~ | | | void* input/code.cpp:38:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 38 | d_right = robot_index < coin_rooms.size()-1 ? coin_rooms[robot_index+1]-coin_rooms[robot_index] : 999999; | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
Code
#include <stdlib.h> #include <iostream> #include <vector> #include <string> int main() { int amount = 0; char* rooms; int robot_index = 0; int steps = 0; int coins = 0; std::cin >> amount; rooms = malloc(amount); std::cin >> rooms[amount]; std::vector<int> coin_rooms; for(int i = 0; i < amount; i++) { switch(rooms[i]) { case '*': coin_rooms.push_back(i); break; case 'R': robot_index = coin_rooms.size(); coin_rooms.push_back(i); break; } } int d_left; int d_right; while(1) { d_left = robot_index > 0 ? coin_rooms[robot_index]-coin_rooms[robot_index-1] : 999999; d_right = robot_index < coin_rooms.size()-1 ? coin_rooms[robot_index+1]-coin_rooms[robot_index] : 999999; if(d_left < d_right) { steps += d_left; coin_rooms.erase(coin_rooms.begin()+robot_index); robot_index--; coins++; } else if(d_right < d_left) { steps += d_right; coin_rooms.erase(coin_rooms.begin()+robot_index); coins++; } else if(d_left == d_right) { break; } } std::cout << steps << " " << coins << "\n"; return 0; }