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

Compiler report

input/code.cpp: In function 'std::string doCycle(std::string)':
input/code.cpp:20:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int index = 0; index < input.size(); index++)
      |                         ~~~~~~^~~~~~~~~~~~~~
input/code.cpp:22:9: error: 'memset' was not declared in this scope
   22 |         memset(bString, 0, sizeof bString);
      |         ^~~~~~
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:41:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             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 gen[100];
bool dontContinue;
string res;
string build(string start, string insert, string end) {
    return start + insert + end;
}

string doCycle(string input) {
    dontContinue = true;
    cout << "Doing cycle for: " << input << endl;
    for (int index = 0; index < input.size(); index++)
    {
        memset(bString, 0, sizeof bString);
        memset(nString, 0, sizeof nString);
        memset(rString, 0, sizeof rString);
        if (isdigit(input[index])) {
            dontContinue = 0;
            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);



    gen[0] = doCycle(inp);
    for (int i = 1; i < 100; i++) {

        gen[i] = doCycle(gen[i-1]);

        cout << "curgen: " << gen[i - 1];
        if (dontContinue == true) {
            res = doCycle(gen[i]);
            
            break;
        }
    }

    

    cout << "Final: " << res;
}