Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void solve() {
- int N; cin >> N;
- vector<string> P(N); F0R(i, N) cin >> P[i];
- vector<vi> pos(N);
- F0R(i, N) {
- F0R(j, sz(P[i])) {
- if (P[i][j] == '*') pos[i].pb(j);
- }
- }
- string st, en;
- F0R(s, N) {
- string cur; F0R(i, pos[s][0]) cur += P[s][i];
- if (sz(cur) > sz(st)) {
- swap(cur, st);
- }
- F0R(i, sz(cur)) if (cur[i] != st[i]) {
- cout << '*' << nl; return;
- }
- }
- F0R(s, N) {
- string cur; FORd(i, pos[s][sz(pos[s])-1] + 1, sz(P[s])) {
- cur += P[s][i];
- }
- if (sz(cur) > sz(en)) {
- swap(cur, en);
- }
- F0R(i, sz(cur)) if (cur[i] != en[i]) {
- cout << '*' << nl; return;
- }
- }
- string ans = st;
- F0R(i, N) {
- F0R(j, sz(P[i])) {
- if (P[i][j] != '*') ans += P[i][j];
- }
- }
- reverse(all(en)); ans += en;
- cout << ans << nl;
- }
Add Comment
Please, Sign In to add comment