CSES - Datatähti 2019 alku - Results
Submission details
Task:Leimasin
Sender:N00B.exe
Submission time:2018-10-13 22:51:51 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:98:2: error: return-statement with no value, in function returning 'int' [-fpermissive]
  return;
  ^~~~~~

Code

#include <iostream>
#include <string>

using namespace std;

bool CheckString(char* s, int count) {
	bool b = true;

	for(int i = count - 1; i > -1; i--)
	{
		b = (*(s + i) == '?');

		if (!b)
		{ break; }
	}

	return b;
}

int Find(char* target, char* main, int targetSize, int mainSize) {
	bool b = false;
	bool qCheck;


	for (int i = 0; i < mainSize; i++)
	{
		b = true;
		for (int k = 0; k < targetSize; k++)
		{
			if (i + targetSize - 1 >= mainSize)
			{ b = false; i = mainSize; break; }

			b = (*(main + i + k) == *(target + k));

			if (!b)
			{ break; }
		}

		if (b)
		{ return i; }
	}

	for(int i = 0; i < mainSize; i++)
	{
		b = true;
		qCheck = false;
		for(int k = 0; k < targetSize; k++)
		{
			if (i + targetSize - 1 >= mainSize)
			{ return -1; }

			b = (*(main + i + k) == *(target + k));
			
			if(!qCheck)
			{ qCheck = (*(main + i + k) != '?'); }

			if(!b)
			{ b = (*(main + i + k) == '?'); }

			if(!b)
			{ break; }
		}

		if(b && qCheck)
		{ return i; }
	}

	return -1;
}

void Remove(char* target, int index, int count) {
	
	if(index == -1)
	{ return; }

	for(int i = index; i < index + count; i++)
	{ *(target + i) = '?'; }
}

void Stamp(char* target, char* stamp, int index, int count) {
	if(index == -1)
	{ return; }

	for(int i = index; i < index + count; i++)
	{ *(target + i) = *(stamp + i - index); }

}

void PrintC(char* c, int count) {
	
	for(int i = 0; i < count; i++)
	{ printf("%c", *(c + i)); }
}

int main()
{
	printf("-1");
	return;
	string target;
	string stamper;

	cin >> target >> stamper;
	int stamperSize = stamper.size();
	int targetSize = target.size();

	if(stamperSize > targetSize)
	{
		printf("-1");
		return 0;
	}

	char* targetC = (char*)malloc(targetSize);
	char * stamperC = (char*)malloc(stamperSize);

	for(int i = 0; i < targetSize; i++)
	{ *(targetC + i) = target[i]; }

	for (int i = 0; i < stamperSize; i++)
	{ *(stamperC + i) = stamper[i]; }

	int maxMoves = 10 * targetSize;
	int* moves = (int*)malloc(4 * maxMoves);
	int totalMoves = 0;
	int index = 0;

	for(int i = 0; i < maxMoves; i++)
	{
		index = Find(stamperC, targetC, stamperSize, targetSize);
		if(index == -1)
		{
			printf("-1");
			return 0;
		}

		Remove(targetC, index, stamperSize);
		*(moves + totalMoves) = index;
		totalMoves++;

		if(CheckString(targetC, targetSize))
		{ break; }
	}

	printf("\n");

	
	printf("%d\n", totalMoves);

	for(int i = totalMoves - 1; i > -1; i--)
	{
		printf("%d", 1 + *(moves + i));

		if(i != 0)
		{ printf(" "); }
	}

	free(moves);
	free(targetC);
	free(stamperC);

	return 0;
}