Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- using namespace std;
- const int N = 1010;
- const int L = 45;
- char a[N][L];
- char s[L];
- int b[L];
- int n, m;
- bool check()
- {
- for (int i = 0; i < n; i++)
- {
- int cnt = 0;
- for (int j = 0; j < m; j++)
- cnt += (int)(s[j] != a[i][j]);
- if (cnt >= 2) return false;
- }
- return true;
- }
- int main()
- {
- scanf("%d", &n);
- for (int i = 0; i < n; i++)
- scanf(" %s ", a[i]);
- m = strlen(a[0]);
- s[m] = (char)0;
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- {
- if (a[i][j] == s[j] || b[j] == 0)
- {
- s[j] = a[i][j];
- b[j]++;
- }
- else
- b[j]--;
- }
- for (int i = 0; i < n; i++)
- {
- int cnt = 0;
- for (int j = 0; j < m; j++)
- cnt += (int)(s[j] != a[i][j]);
- if (cnt <= 1) continue;
- if (cnt != 2) throw;
- for (int j = 0; j < m; j++)
- {
- if (s[j] == a[i][j]) continue;
- char old = s[j];
- s[j] = a[i][j];
- if (check())
- {
- printf("%s\n", s);
- return 0;
- }
- s[j] = old;
- }
- throw;
- }
- printf("%s\n", s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement