Advertisement
Asif_Anwar

UVA-12662

Jul 26th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. //using namespace chrono;
  5.  
  6. typedef long long ll;
  7. typedef vector< int > vi;
  8. typedef vector< ll > V;
  9. typedef map<int, int > mp;
  10.  
  11. #define pb push_back
  12. #define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  13. #define F first
  14. #define S second
  15.  
  16. #define debug cout << -1 << endl;
  17. #define REP(i, a, b) for(int i=a; i<b; i++)
  18. #define f0r(i, n) for (int i = 0; i < n; ++i)
  19. #define f0r1(i, n) for (int i = 1; i <= n; ++i)
  20. #define r0f(i, n) for(int i=n-1; i>=0; i--)
  21. #define r0f1(i, n) for(int i=n; i>=1; i--)
  22. #define fore(a, x) for (auto& a : x)
  23. #define fori(i, a, b) for (int i = (a); i < (b); ++i)
  24.  
  25. #define MP make_pair
  26. #define UB upper_bound
  27. #define LB lower_bound
  28. #define nw cout << "\n"
  29.  
  30. #define issq(x) (((ll)(sqrt((x))))*((ll)(sqrt((x))))==(x))
  31. #define rev(v) reverse(v.begin(),v.end())
  32. #define asche cerr<<"Ekhane asche\n";
  33. #define rev(v) reverse(v.begin(),v.end())
  34. #define srt(v) sort(v.begin(),v.end())
  35. #define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())
  36. #define all(v) v.begin(),v.end()
  37. #define mnv(v) *min_element(v.begin(),v.end())
  38. #define mxv(v) *max_element(v.begin(),v.end())
  39. #define valid(tx,ty) (tx>=0 && tx<n && ty>=0 && ty<m)
  40. #define one(x) __builtin_popcount(x)
  41. //#define pop pop_back
  42. #define setPrec(x) cout << fixed << setprecision(x)
  43. #define sz(a) (int)a.size()
  44. //#define fin cin
  45. //#define fout cout
  46. const int INF = 1e9;
  47. const ll MOD = (ll)1e9+7;
  48. const ll INFL = 1e18;
  49. const ll mnINF = -1e18;
  50. const double diff = 10e-6;
  51. const int maxn = 200005;
  52. const double PI = acos(-1);
  53. using namespace std;
  54.  
  55. // int dx[] = {-1, 0, 1};
  56. // int dy[] = {-1, 0, 1};
  57.  
  58. int dx[] = {-1, 0, 0, 1};
  59. int dy[] = {0, -1, 1, 0};
  60.  
  61. void solve()
  62. {
  63.     int n;
  64.     cin >> n;
  65.     vector< string > v(n);
  66.     f0r(i, n) cin >> v[i];
  67.     int m;
  68.     cin >> m;
  69.     while(m--) {
  70.         int x;
  71.         cin >> x;
  72.         int lt = 0, rt = 0;
  73.         int cntl = 0, cntr = 0;
  74.         bool lf = false, rf = false;
  75.         x--;
  76.         if(v[x]!="?") {
  77.             cout << v[x] << "\n";
  78.             continue;
  79.         }
  80.         for(int i=x; i>=0; i--) {
  81.             if(v[i]!="?") {
  82.                 lf = true;
  83.                 lt = i;
  84.                 break;
  85.             }
  86.             cntl++;
  87.         }
  88.         for(int i=x; i<n; i++) {
  89.             if(v[i]!="?") {
  90.                 rf = true;
  91.                 rt = i;
  92.                 break;
  93.             }
  94.             cntr++;
  95.         }
  96.         if(lf && rf && cntl==cntr) {
  97.             cout << "middle of " << v[lt] << " and " << v[rt] << "\n";
  98.         }
  99.         else if(lf && rf){
  100.             if(cntl<cntr){
  101.                 f0r(z, cntl) {
  102.                     cout << "right of ";
  103.                 }
  104.                 cout << v[lt] << "\n";
  105.             }
  106.             else {
  107.                 f0r(z, cntr) {
  108.                     cout << "left of ";
  109.                 }
  110.                 cout << v[rt] << "\n";
  111.             }
  112.         }
  113.         else if(lf) {
  114.             f0r(z, cntl) {
  115.                 cout << "right of ";
  116.             }
  117.             cout << v[lt] << "\n";
  118.         }
  119.         else {
  120.             f0r(z, cntr) {
  121.                 cout << "left of ";
  122.             }
  123.             cout << v[rt] << "\n";
  124.         }
  125.     }    
  126. }
  127.  
  128. void setIO(string name = "") { // name is nonempty for USACO file I/O
  129.  
  130.     ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output
  131.  
  132.     // alternatively, cin.tie(0)->sync_with_stdio(0);
  133.  
  134.     if (name.size()) {
  135.  
  136.         freopen((name+".in").c_str(), "r", stdin); // see Input & Output
  137.  
  138.         freopen((name+".out").c_str(), "w", stdout);
  139.  
  140.     }
  141.  
  142. }
  143.  
  144. int main()
  145. {
  146. #ifndef ONLINE_JUDGE
  147.     freopen("inputf.in", "r", stdin);
  148.     freopen("outputf.in", "w", stdout);
  149. #endif
  150.     //setIO("breedflip");
  151.     FastIO;
  152.     int t;
  153.     t = 1;
  154.     // cin >> t;
  155.     f0r(i, t) {
  156.         //cout << "Case " << i+1 << ": ";
  157.         solve();
  158.     }
  159.     return 0;
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement