CSES - Datatähti 2024 alku - Results
Submission details
Task:Monistus
Sender:snowflake
Submission time:2024-02-12 18:12:56 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'std::string process(const string&)':
input/code.cpp:9:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     while (i < s.size())
      |            ~~^~~~~~~~~~
input/code.cpp:14:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |             if (i + repeatCount >= s.size())
      |                 ~~~~~~~~~~~~~~~~^~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:38:5: error: 'ios_base' has not been declared
   38 |     ios_base::sync_with_stdio(false);
      |     ^~~~~~~~
input/code.cpp:39:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   39 |     cin.tie(0);
      |     ^~~
      |     std::cin
In file included from input/code.cpp:1:
/usr/include/c++/11/iostr...

Code

#include <iostream>
#include <string>

std::string process(const std::string& s)
{
    std::string result = "";
    int i = 0;

    while (i < s.size())
    {
        if (isdigit(s[i])) {
            int repeatCount = s[i] - '0'; // Convert digit character to integer
            int substrStart = i + 1;
            if (i + repeatCount >= s.size())
            {
                break; // Not enough characters left to duplicate
            }
            
            // Repeat the substring
            for (int j = 0; j < repeatCount; ++j)
            {
                result += s.substr(substrStart, repeatCount); 
            }
            i += repeatCount + 1; // Skip ahead past the digit and duplicated substring
        }
        else
        {
            result += s[i]; // Copy letters as is
            i++;
        }
    }

    return result;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    string soho;
    cin >> soho;

    std::string oute = process(soho);

    cout << oute;

    return 0;
}