본문 바로가기
PS(Problem Solving)/백준_BOJ

[백준] 2160번 - 그림 비교 (C++) 문제 및 풀이

by 초코칩프라푸치노 2022. 2. 16.

문제) 백준 - 구현 - 그림 비교

https://www.acmicpc.net/problem/2160

 

2160번: 그림 비교

N(2 ≤ N ≤ 50)개의 그림이 있다. 각각의 그림은 5×7의 크기이고, 두 가지 색으로 되어 있다. 이때 두 가지의 색을 각각 ‘X’와 ‘.’으로 표현하기로 하자. 이러한 그림들이 주어졌을 때, 가장 비

www.acmicpc.net


반복문으로 하나씩 저장 후 비교하여 가장 비슷한 것을 출력합니다.

 

C++ 소스코드)

#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define INF 987654321
#define MAX 51
#define MOD 10007
using namespace std;
typedef pair<int, int> p;
int N;
string board[MAX][5];
int sim(int x, int y){
int res = 0;
for(int i = 0; i < 5; ++i)
for(int j = 0; j < 7; ++j)
if(board[x][i][j] == board[y][i][j])
res++;
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> N;
for(int i = 1; i <= N; ++i)
for(int j = 0; j < 5; ++j)
cin >> board[i][j];
int cnt = -1;
int f, s;
for(int i = 1; i <= N; ++i)
for(int j = i + 1; j <= N; ++j)
if(cnt < sim(i, j)){
cnt = sim(i, j);
f = i; s = j;
}
cout << f << " " << s;
return 0;
}
view raw 2160.cpp hosted with ❤ by GitHub

 

반응형

댓글