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

Compiler report

input/code.cpp: In function 'std::string runCycle(const char*)':
input/code.cpp:17:9: error: 'memset' was not declared in this scope
   17 |         memset(bWord, 0, sizeof bWord);
      |         ^~~~~~
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>

Code

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

char bWord[100], mWord[100], eWord[100], input[20], tem[100];
string generation;
bool done;
int findDigit(const char inp[20]) {
	for (int i = 0; i < 20; i++) 
	{ 
		if (isdigit(inp[i])) return i; 
	}
	return -1;
}
string runCycle(const char inp[20])
{
	memset(bWord, 0, sizeof bWord);
	memset(mWord, 0, sizeof mWord);
	memset(eWord, 0, sizeof eWord);
	int numberIndex = findDigit(inp);
	if (numberIndex == -1) {
		done = true;
		return inp;
	}
	
	for (int i = 0; i < 20; i++) {
		if (i < numberIndex) 
		{
			bWord[i] = inp[i];
		}
		else if (i < (numberIndex + inp[numberIndex] - 48)) {
			mWord[i - numberIndex] = inp[i + 1];
			eWord[i - numberIndex] = inp[i + 1];
		}
		else
		{
			eWord[i - numberIndex] = inp[i + 1];
		}
	}
	//cout << "Beginning word: " << bWord << endl << "Insert Word: " << mWord << endl << "Ending word: " << eWord << endl;
	return string(bWord) + string(mWord) + string(eWord);
}
int main() {
	cin >> input;
	
	generation = runCycle(input);
	for (int i = 0; i < 50; i++) 
	{
		for (int j = 0; j < int(generation.length()); j++) tem[j] = generation[j];
		
		generation = runCycle(tem);
		if (done == true) {
			cout << generation;
			return 0;
		}
	}
	cout << generation;
	return 0;
}