CSES - Datatähti 2020 alku - Results
Submission details
Task:Merkkijonot
Sender:nikohann
Submission time:2019-10-03 21:36:47 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool onkoHarmoninen(std::__cxx11::string, std::__cxx11::string)':
input/code.cpp:15:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < s1.length(); i++) {
                   ~~^~~~~~~~~~~~~
input/code.cpp:17:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < s2.length(); k++) {
                    ~~^~~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:71:68: error: no matching function for call to 'find(std::vector<std::__cxx11::basic_string<char> >::iterator, std::vector<std::__cxx11::basic_string<char> >::iterator, std::__cxx11::string&)'
    if (std::find(harmonisetParit.begin(), harmonisetParit.end(), s2) != harmonisetParit.end()) continue;
                                                                    ^
In file included from /usr/include/c++/7/bits/locale_facets.h:48:0,
                 from /usr/include/c...

Code

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

bool onkoHarmoninen(string s1, string s2) {

	if (s1 == s2) return false;

	if (s1.length() == s2.length()) {

		bool ehto_1 = false;
		bool ehto_2 = false;

		for (int i = 0; i < s1.length(); i++) {

			for (int k = 0; k < s2.length(); k++) {

				if (i == k) continue;

				if (ehto_1 && ehto_2) {
					return true;
				}
				
				//Ehto1
				if (s1[i] == s1[k]) {

					if (s2[i] == s2[k]) {

						ehto_1 = true;
						continue;
					}
				}

				//Ehto 2
				if (s1[i] != s1[k]) {

					if (s2[i] != s2[k]) {
						ehto_2 = true;
						continue;
					}
				}


			}
		}
	}
	return false;
}
int main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, harmoniset = 0;
	vector<string> v, harmonisetParit;
	string temp;

	
	scanf("%d", &n);
	for (int i = 0; i <= n; i++) {
		getline(cin, temp);
		v.push_back(temp);
	}

	for (string s1 : v) {

		for (string s2 : v) {
		
			if (std::find(harmonisetParit.begin(), harmonisetParit.end(), s2) != harmonisetParit.end()) continue;

			if (onkoHarmoninen(s1, s2)) {
				harmoniset++;
				harmonisetParit.push_back(s1);

			}
		}

	}

	harmoniset += 1;
	printf("%d", harmoniset);
	return 0;	
}