fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int N;
  9. cin >> N;
  10. string SS, SK, SH;
  11. cin >> SS >> SK >> SH;
  12.  
  13. string ans(N, 'a');
  14. int scoreS = 0, scoreK = 0, scoreH = 0;
  15.  
  16. for (int i = 0; i < N; i++) {
  17. // case: 세 명 다 같은 글자
  18. if (SS[i] == SK[i] && SK[i] == SH[i]) {
  19. // 셋 다 맞추면 동점 → 틀리게
  20. char c = (SS[i] == 'a' ? 'b' : 'a');
  21. ans[i] = c;
  22. continue;
  23. }
  24.  
  25. // case: 둘만 같은 경우
  26. if (SS[i] == SK[i] && SS[i] != SH[i]) {
  27. // 숭+고 동시에 점수 → 위험 (동점 발생할 수 있음)
  28. // 기본은 숭돌이만 주고 싶은데 불가능.
  29. // 여기선 일단 틀리게 해서 점수 안 줌.
  30. ans[i] = (SS[i] == 'a' ? 'b' : 'a');
  31. if (ans[i] == SS[i]) scoreS++;
  32. if (ans[i] == SK[i]) scoreK++;
  33. if (ans[i] == SH[i]) scoreH++;
  34. continue;
  35. }
  36. if (SS[i] == SH[i] && SS[i] != SK[i]) {
  37. // 숭+한 같이 점수 → 절대 주면 안됨
  38. // 따라서 고돌이 답 선택
  39. ans[i] = SK[i];
  40. if (ans[i] == SS[i]) scoreS++;
  41. if (ans[i] == SK[i]) scoreK++;
  42. if (ans[i] == SH[i]) scoreH++;
  43. continue;
  44. }
  45. if (SK[i] == SH[i] && SS[i] != SK[i]) {
  46. // 고+한 같이 점수 → 위험
  47. // 숭돌이 답 선택
  48. ans[i] = SS[i];
  49. if (ans[i] == SS[i]) scoreS++;
  50. if (ans[i] == SK[i]) scoreK++;
  51. if (ans[i] == SH[i]) scoreH++;
  52. continue;
  53. }
  54.  
  55. // case: 셋 다 다름
  56. // 숭돌이 답 우선
  57. ans[i] = SS[i];
  58. if (ans[i] == SS[i]) scoreS++;
  59. if (ans[i] == SK[i]) scoreK++;
  60. if (ans[i] == SH[i]) scoreH++;
  61. }
  62.  
  63. // 최종 점검
  64. if (scoreS > scoreK && scoreK > scoreH) {
  65. cout << ans << "\n";
  66. } else {
  67. cout << -1 << "\n";
  68. }
  69. }
Success #stdin #stdout 0s 5320KB
stdin
5
abcde
efgtb
abgte
stdout
-1