Combothermal

Untitled

Apr 10th, 2020
908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. void solve() {
  2. int N; cin >> N;
  3. vector<string> P(N); F0R(i, N) cin >> P[i];
  4. vector<vi> pos(N);
  5. F0R(i, N) {
  6. F0R(j, sz(P[i])) {
  7. if (P[i][j] == '*') pos[i].pb(j);
  8. }
  9. }
  10.  
  11.  
  12. string st, en;
  13. F0R(s, N) {
  14. string cur; F0R(i, pos[s][0]) cur += P[s][i];
  15. if (sz(cur) > sz(st)) {
  16. swap(cur, st);
  17. }
  18. F0R(i, sz(cur)) if (cur[i] != st[i]) {
  19. cout << '*' << nl; return;
  20. }
  21. }
  22.  
  23. F0R(s, N) {
  24. string cur; FORd(i, pos[s][sz(pos[s])-1] + 1, sz(P[s])) {
  25. cur += P[s][i];
  26. }
  27. if (sz(cur) > sz(en)) {
  28. swap(cur, en);
  29. }
  30. F0R(i, sz(cur)) if (cur[i] != en[i]) {
  31. cout << '*' << nl; return;
  32. }
  33. }
  34.  
  35. string ans = st;
  36. F0R(i, N) {
  37. F0R(j, sz(P[i])) {
  38. if (P[i][j] != '*') ans += P[i][j];
  39. }
  40. }
  41. reverse(all(en)); ans += en;
  42. cout << ans << nl;
  43.  
  44. }
Add Comment
Please, Sign In to add comment