CSES - Datatähti 2024 alku - Results
Submission details
Task:Monistus
Sender:Bean Benestrom
Submission time:2023-10-30 10:32:35 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'std::string solve(const string&)':
input/code.cpp:8:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i=0; i < string.length(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:25:17: error: redeclaration of 'std::string string'
   25 |     std::string string = solve(string);
      |                 ^~~~~~
input/code.cpp:23:17: note: 'std::string string' previously declared here
   23 |     std::string string;
      |                 ^~~~~~

Code

#include <iostream>
#include <string>

std::string solve(const std::string& string) {
    std::string solved_string;
    char c;
    int  v;
    for (int i=0; i < string.length(); i++) {
        c = string[i];
        v = string[i] - '0';
        if (0 < v && v < 10) { 
            solved_string += solve(string.substr(i+1, v)); 
            continue;
        }
        solved_string += c;
    }
    return solved_string;
}


int main()
{
    std::string string;
    std::cin >> string;
    std::string string = solve(string);
    std::cout << string << '\n';
    return 0;
}