끄적끄적 코딩
article thumbnail

브루트포스로 문제를 해결했습니다.

겹치지 않는 부분이 가장 적은 곳들의 인덱스를 출력했습니다.

 

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#define MAX 987654321

using namespace std;

int main(int argc, char* argv[])
{
	bool flag;
	int n;
	int count;
	int x, y;
	int result = MAX;
	char map[5][7][50];
	string s;

	memset(map, 0, sizeof(map));

	cin >> n;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 5; ++j) {
			cin >> s;
			for (int k = 0; k < 7; ++k) {
				map[j][k][i] = s[k];
			}
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (i == j) {
				continue;
			}
			flag = false;
			count = 0;
			for (int k = 0; k < 5; ++k) {
				for (int l = 0; l < 7; ++l) {
					if (map[k][l][i] != map[k][l][j]) {
						++count;
					}
					if (count > result) {
						flag = true;
						break;
					}
				}
				if (flag) {
					break;
				}
			}
			if (result > count) {
				result = count;
				x = i;
				y = j;
			}
		}
	}

	cout << x + 1 << " " << y + 1 << endl;

	return 0;
}

검색 태그