CSES - Datatähti 2020 alku - Results
Submission details
Task:Merkkijonot
Sender:2
Submission time:2019-09-30 18:49:23 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool onko_h(const string&, const string&)':
input/code.cpp:12:5: error: 'memset' was not declared in this scope
     memset((void*)a_vastaavat_c, 0, 128);
     ^~~~~~
input/code.cpp:12:5: note: suggested alternative: 'wmemset'
     memset((void*)a_vastaavat_c, 0, 128);
     ^~~~~~
     wmemset
input/code.cpp:15:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.length(); i++)
                  ~~^~~~~~~~~~~~
input/code.cpp:20:29: warning: array subscript has type 'char' [-Wchar-subscripts]
         if(a_vastaavat_c[a_m] != 0 && b_vastaavat_c[b_m] != 0)
                             ^
input/code.cpp:20:56: warning: array subscript has type 'char' [-Wchar-subscripts]
         if(a_vastaavat_c[a_m] != 0 && b_vastaavat_c[b_m] != 0)
                                                        ^
input/code.cpp:29:33: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(a_vastaava...

Code

#include <iostream>
#include <vector>
#include <map>

bool onko_h(const std::string& a, const std::string& b)
{
	if (a.length() != b.length()) return false;

	//std::map<char, char> a_vastaavat, b_vastaavat;
    char a_vastaavat_c[128], b_vastaavat_c[128];
    memset((void*)a_vastaavat_c, 0, 128);
    memset((void*)b_vastaavat_c, 0, 128);

	for (int i = 0; i < a.length(); i++)
	{
		char a_m = a[i];
		char b_m = b[i];
		//if (a_vastaavat.count(a_m) == 1 || b_vastaavat.count(b_m) == 1)
        if(a_vastaavat_c[a_m] != 0 && b_vastaavat_c[b_m] != 0)
		{
			// Mapping established
			/*
            if (a_vastaavat[a_m] != b_m)
				return false;
			if (b_vastaavat[b_m] != a_m)
				return false;
            */
            if(a_vastaavat_c[a_m] != b_m && b_vastaavat_c[b_m] != a_m)
                return false;
		}
		else
		{
			// Establish mapping
			//a_vastaavat[a_m] = b_m;
			//b_vastaavat[b_m] = a_m;
            a_vastaavat_c[a_m] = b_m;
            b_vastaavat_c[b_m] = a_m;
		}
	}
	return true;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);

	int n;
	std::cin >> n;
	std::vector<std::string> mj;
    mj.resize(n);
	for (int i = 0; i < n; i++)
	{
		std::string s;
		std::cin >> s;
		mj[i] = s;
	}

	int harm_c = 0;
	for (int i = 0; i < mj.size(); i++)
	{
		for (int k = i; k < mj.size(); k++)
		{
			if (i != k)
			{
				if (onko_h(mj[i], mj[k]))
					harm_c++;
			}
		}
	}
	std::cout << harm_c;
	return 0;
}