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 S = SS;
  14. int scoreS = 0, scoreK = 0, scoreH = 0;
  15.  
  16. for (int i = 0; i < N; i++) {
  17. if (S[i] == SS[i]) scoreS++;
  18. if (S[i] == SK[i]) scoreK++;
  19. if (S[i] == SH[i]) scoreH++;
  20. }
  21.  
  22. if (scoreS > scoreK && scoreK > scoreH) {
  23. cout << S << "\n";
  24. return 0;
  25. }
  26.  
  27. for (int i = 0; i < N; i++) {
  28. // 현재 점수 차감
  29. int oldS = (S[i] == SS[i]);
  30. int oldK = (S[i] == SK[i]);
  31. int oldH = (S[i] == SH[i]);
  32.  
  33. // 고돌이가 한돌이와 다르면, 고돌이만 맞게 선택할 수 있음
  34. if (SK[i] != SH[i]) {
  35. int newS = (SK[i] == SS[i]);
  36. int newK = 1;
  37. int newH = 0;
  38.  
  39. int tmpS = scoreS - oldS + newS;
  40. int tmpK = scoreK - oldK + newK;
  41. int tmpH = scoreH - oldH + newH;
  42.  
  43. if (tmpS > tmpK && tmpK > tmpH) {
  44. S[i] = SK[i];
  45. cout << S << "\n";
  46. return 0;
  47. }
  48. }
  49. }
  50.  
  51. cout << -1 << "\n";
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
abcde
efgtb
abgte
stdout
-1