CSES - Datatähti 2019 alku - Results
Submission details
Task:Leimasin
Sender:2
Submission time:2018-10-05 13:20:50 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void solve(const string&, const string&, std::vector<int>&)':
input/code.cpp:36:3: error: 'memset' was not declared in this scope
   memset((void*) resstring.data(), '?', resstring.length());
   ^~~~~~
input/code.cpp:36:3: note: suggested alternative: 'wmemset'
   memset((void*) resstring.data(), '?', resstring.length());
   ^~~~~~
   wmemset
input/code.cpp:39:4: error: 'memcpy' was not declared in this scope
    memcpy(&resstring[i - 1], stamp.data(), stamp.size());
    ^~~~~~
input/code.cpp:39:4: note: suggested alternative: 'wmemcpy'
    memcpy(&resstring[i - 1], stamp.data(), stamp.size());
    ^~~~~~
    wmemcpy

Code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>


void solve(const std::string& str, const std::string& stamp, std::vector<int>& result)
{
	auto pos = str.find(stamp);
	if(pos == std::string::npos) 
		return;

	for(int i = 0; i < ((int) str.length() - (int)stamp.length() + 1); i++)
	{
		for(int k = 0; k < (int) stamp.length(); k++)
		{
			if(str.substr(i, stamp.length()) == stamp)
			{
				result.push_back(i + 1);
				i += stamp.length() - 2;
				break;
			}
			if(str[i + k] == stamp[k])
			{
				result.push_back(i + 1);
				
				break;
			}
		}
	}

	std::string resstring;
	resstring.resize(str.size());
	do
	{
		memset((void*) resstring.data(), '?', resstring.length());
		for(int i : result)
		{
			memcpy(&resstring[i - 1], stamp.data(), stamp.size());
		}
		if(resstring == str)
		{
			return;
		}
	}
	while(std::next_permutation(result.begin(), result.end()));
	result.clear();
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	// = "ABCDABCDABCDABCD"
	// = "ABCD"
	std::string str, stamp;	
	std::cin >> str;
	std::cin >> stamp;

	std::vector<int> res;
	solve(str, stamp, res);
	if(res.size() != 0)
	{
		std::cout << res.size() << "\n";
		for(int a : res)
		{
			std::cout << a << " ";
		}
	}
	else
	{
		std::cout << "-1";
	}

	// std::system("pause");
}