CSES - Datatähti 2024 alku - Results
Submission details
Task:Monistus
Sender:Oliver2
Submission time:2023-10-31 18:47:38 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'std::string doCycle(std::string)':
input/code.cpp:18:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int index = 0; index < input.size(); index++)
      |                         ~~~~~~^~~~~~~~~~~~~~
input/code.cpp:20:9: error: 'memset' was not declared in this scope
   20 |         memset(bString, 0, 255);
      |         ^~~~~~
input/code.cpp:2:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
    1 | #include <iostream>
  +++ |+#include <cstring>
    2 | #include <string>
input/code.cpp:38:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             for (int k = 1; (k + index) < input.size(); k++) {
      |                             ~~~~~~~~~~~~^...

Code

#include <iostream>
#include <string>
using namespace std;

string inp;
char bString[1000]; 
char nString[9];
char rString[1000];
int indexSize;
string gen1, gen2, gen3;

string build(string start, string insert, string end) {
    return start + insert + end;
}

string doCycle(string input) {
    cout << "Doing cycle for: " << input << endl;
    for (int index = 0; index < input.size(); index++) 
    {
        memset(bString, 0, 255);
        memset(nString, 0, 255);
        memset(rString, 0, 255);
        if (isdigit(input[index])) {
            for (int x = 0; x < index; x++) {
                bString[x] = input[x];
            }

            indexSize = input[index] - 48;
            cout << "number" << indexSize << "found at " << index;


            for (int j = 1; j <= indexSize; j++)
            {
                nString[j - 1] = input[index + j]; //nstring = we insert into middle

            }

            for (int k = 1; (k + index) < input.size(); k++) {
                rString[k - 1] = input[index + k]; //rstring we add to the end
            }
            cout << endl << " Start of string: " << bString << endl;
            cout << endl << " Insert into middle: " << nString << endl;
            cout << endl << " Insert into end: " << rString << endl;
            return build(bString, nString, rString);
        }
        
    }
    return input;
}
int main() {
    getline(cin, inp);
    gen1 = doCycle(inp);
    gen2 = doCycle(gen1);
    gen3 = doCycle(gen2);
    cout << "Final: " << gen3;


}