CSES - Datatähti 2025 alku - Results
Submission details
Task:Robotti
Sender:jokeri2222
Submission time:2024-10-29 10:47:31 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:16:25: error: invalid conversion from 'const char*' to 'char' [-fpermissive]
   16 |             char left = "";
      |                         ^~
      |                         |
      |                         const char*
input/code.cpp:17:26: error: invalid conversion from 'const char*' to 'char' [-fpermissive]
   17 |             char right = "";
      |                          ^~
      |                          |
      |                          const char*
input/code.cpp:26:22: warning: comparison with string literal results in unspecified behavior [-Waddress]
   26 |             if (left == "*" && right == "*") {
      |                 ~~~~~^~~~~~
input/code.cpp:26:22: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
input/code.cpp:26:38: warning: comparison with string literal results in unspecified behavior [-Waddress]
   26 |             if (left == "*" && right == "*") {
      |...

Code

#include <iostream>

using namespace std;

int main() {
    int _len;
    string s;
    cin >> _len;
    cin >> s;
    
    int index = s.find("R", 0);
    int steps = 0, coins = 0;
    bool found = false;
    for (int i=0; i<_len; i++) {
        for (int step=0; step<_len; step++) {
            char left = "";
            char right = "";
            
            if (index-step > 0) {
                left = s[index-step];
            }
            if (index+step < _len) {
                right = s[index+step];
            }
            
            if (left == "*" && right == "*") {
                cout << steps << " " << coins;
                return 0;
            }
            if (left == "*") {
                coins++;
                steps+=step;
                s[index] = '.';
                s[index-step] = 'R';
                index -= step;
                found = true;
            }
            if (right == "*") {
                coins++;
                steps+=step;
                s[index] = '.';
                s[index+step] = 'R';
                index += step;
                found = true;
            }
        }
        if (!found) {
            break;
        }
    }
    
    cout << steps << " " << coins;

    return 0;
}