CSES - Datatähti 2020 alku - Results
Submission details
Task:Merkkijonot
Sender:jusola
Submission time:2019-10-02 21:32:41 +0300
Language:C++11
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'std::__cxx11::string toFormat(std::__cxx11::string)':
input/code.cpp:72:2: error: 'strcpy_s' was not declared in this scope
  strcpy_s(arrStr, in.c_str());
  ^~~~~~~~
input/code.cpp:72:2: note: suggested alternative: 'strcpy'
  strcpy_s(arrStr, in.c_str());
  ^~~~~~~~
  strcpy
input/code.cpp: In function 'int main()':
input/code.cpp:92:2: error: 'strcpy_s' was not declared in this scope
  strcpy_s(alphabetArr, alphabet.c_str());
  ^~~~~~~~
input/code.cpp:92:2: note: suggested alternative: 'strcpy'
  strcpy_s(alphabetArr, alphabet.c_str());
  ^~~~~~~~
  strcpy

Code

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <stdio.h>
#include <string.h>

using namespace std;

const string alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

char alphabetArr[54];




/*
bool isPair(const string a = 0, const string b = 0) {
	std::unordered_map<char, char> mapA;
	std::unordered_map<char, char> mapB;

	std::unordered_map<char, char>::iterator it;

	char arrA[50];
	char arrB[50];

	string newA;
	string newB;

	strcpy_s(arrA, a.c_str());
	strcpy_s(arrB, b.c_str());

	for (int i = 0; i < (int)a.size(); i++) {
		if (mapA.find(arrA[i]) != mapA.end()) {
			newA = newA + std::string(1, mapA.find(arrA[i])->second);
		}
		else {
			newA = newA + std::string(1, alphabetArr[(int)mapA.size()]);
			mapA.insert(std::pair<char, char>(arrA[i], alphabetArr[(int)mapA.size()]));

		}

	}

	for (int i = 0; i < (int)b.size(); i++) {
		if (mapB.find(arrB[i]) != mapB.end()) {
			newB = newB + std::string(1, mapB.find(arrB[i])->second);
		}
		else {
			newB = newB + std::string(1, alphabetArr[(int)mapB.size()]);
			mapB.insert(std::pair<char, char>(arrB[i], alphabetArr[(int)mapB.size()]));

		}

	}
	return (newA == newB);
}
*/

string toFormat(const string in) {
	std::unordered_map<char, char> mapStr;

	std::unordered_map<char, char>::iterator it;

	char arrStr[50];

	string newStr;

	strcpy_s(arrStr, in.c_str());

	for (int i = 0; i < (int)in.size(); i++) {
		if (mapStr.find(arrStr[i]) != mapStr.end()) {
			newStr = newStr + std::string(1, mapStr.find(arrStr[i])->second);
		}
		else {
			newStr = newStr + std::string(1, alphabetArr[(int)mapStr.size()]);
			mapStr.insert(std::pair<char, char>(arrStr[i], alphabetArr[(int)mapStr.size()]));

		}

	}

	return newStr;
}

int main() {
	int num;
	int amount = 0;
	strcpy_s(alphabetArr, alphabet.c_str());
	string arr[5000];
	string newArr[5000];
	std::unordered_map<string, int> CountSame;
	cin >> num;

	for (int i = 0; i < num; i++) {
		cin >> arr[i];
	}
	for (int i = 0; i < num; i++) {
		newArr[i] = toFormat(arr[i]);
		if (CountSame.find(newArr[i]) != CountSame.end()) {
			CountSame[newArr[i]] = CountSame.find(newArr[i])->second+1;
		}
		else {
			CountSame[newArr[i]] = 1;
		}
	};

	for (std::unordered_map<string, int>::iterator it = CountSame.begin(); it != CountSame.end(); ++it)
	{
		amount += (it->second * (it->second - 1))/2;
	}

	cout << amount;
	return 0;
}