fork(1) download
  1. //***************************************\\
  2. //********Author -- Raju Varshney********\\
  3. //***************************************\\
  4. #include<stdio.h>
  5. #include<stdlib.h>
  6. #include<math.h>
  7. #include<time.h>
  8. #include<utility>
  9. #include<algorithm> //min,max,swap(a,b),sort
  10. #include<list>
  11. #include<vector>
  12. #include<set>
  13. #include<map>
  14. #include<string>
  15. #include<iostream>
  16. #include<deque>
  17. #include<string>
  18. using namespace std;
  19. #include<bits/stdc++.h>
  20. typedef unsigned long long ull;
  21. typedef long long ll;
  22. typedef vector<int> vi;
  23. typedef vector<vi> vvi;
  24. typedef pair<int,int> pii;
  25. #define sz(a) int((a).size())
  26. #define pb push_back
  27. #define mpa make_pair
  28. #define fi first
  29. #define se second
  30. #define all(c) (c).begin(),(c).end()
  31. #define tr(c,i) for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
  32. #define present(c,x) ((c).find(x) != (c).end())
  33. #define cpresent(c,x) (find(all(c),x) != (c).end())
  34. #define abs(x) ((x)>0?(x):-(x))
  35. #define si(i) scanf("%d",&i)
  36. #define sl(i) scanf("%I64d",&i)
  37. #define sf(i) scanf("%f",&i)
  38. #define ss(i) cin>>i
  39. #define pi(i) printf("%d ",i)
  40. #define pni(i) printf("%d \n",i)
  41. #define pl(i) printf("%I64d ",i)
  42. #define pnl(i) printf("%I64d \n",i)
  43. #define pf(i) printf("%f ",i)
  44. #define pnf(i) printf("%f \n",i)
  45. #define ps(i) cout<<i
  46. #define pns(i) cout<<i<<'\n'
  47. #define gcd(a,b) std::__gcd(a,b)
  48. #define lcm(a,b) (a*b)/gcd(a,b)
  49. #define lcm1(a,b) (a*b)/gcd1(a,b)
  50. #define loop(i,x,n) for(int i=x;i<n;i++)
  51. #define lb(v,x) lower_bound(v.begin(), v.end(), x)-v.begin() // frst element jst >=
  52. #define ub(v,x) upper_bound(v.begin(), v.end(), x)-v.begin() // frst element jst >
  53. #define strlower(a) transform(a.begin(), a.end(), a.begin(), ::tolower)
  54. #define strupper(a) transform(a.begin(), a.end(), a.begin(), ::toupper)
  55. #define pfloat(a,b) cout<<setprecision(b)<<fixed<<a<<' '
  56. #define pnfloat(a,b) cout<<setprecision(b)<<fixed<<a<<'\n'
  57. #define starttime clock_t t1time;t1time=clock()
  58. #define stoptime t1time=clock()-t1time;double time_taken=((double)t1time)/CLOCKS_PER_SEC;printf("program take %f seconds to execute \n", time_taken)
  59. #define MOD 1000000007
  60.  
  61. //Remember that set and map have the member functions find() and count(), which works in O(log N), while std::find() and std::count() take O(N).
  62. /*
  63.  
  64. ll gcd1(ll a , ll b)
  65. {
  66.   if(b==0) return a;
  67.   a%=b;
  68.   return gcd(b,a);
  69. }
  70. int add(int a, int b) {
  71. a += b;
  72. if (a >= MOD) a -= MOD;
  73. return a;
  74. }
  75.  
  76. int sub(int a, int b) {
  77. a -= b;
  78. if ( a < 0 ) a += MOD;
  79. return a;
  80. }
  81.  
  82. int mul(int a, int b) {
  83. return ((long long)a) * b % MOD;
  84. }
  85.  
  86. int expmod(int a, int b) {
  87. long long x = 1, y = a;
  88. while(b) {
  89. if (b & 1) x = mul(x, y);
  90. y = mul(y, y);
  91. b >>= 1;
  92. }
  93. return x;
  94. }
  95. */
  96. // itoa(num, str, base); str must be in form char str[n];
  97. /*
  98. typedef struct point{
  99.   int x, y;
  100. }point;
  101.  
  102. bool cmp(point a, point b) {
  103.   if(a.x==b.x)
  104.   return a.y<b.y;
  105.   return a.x < b.x;
  106. }
  107. sort(a,a+n,cmp);
  108.  
  109. */
  110. //vi v1(size,-1);
  111. //vvi v2 (size1, v1);
  112. //vector<pair<pii,int> >E;
  113. //E.pb(mpa(mpa(u,v),x));
  114.  
  115.  
  116. int main(){
  117. // freopen("a.txt","r",stdin);
  118. // freopen("bb.txt","w",stdout);
  119. // clock_t t1;
  120. // t1=clock();
  121. int t;si(t);
  122. string s;
  123. loop(ii,0,t){
  124. ss(s);
  125. list<char> my;
  126. list<char>:: iterator it;
  127. list<char>:: iterator jj;
  128. it=my.begin();
  129. loop(j,0,s.length()){
  130.  
  131. if(s[j]=='<'){
  132. if(sz(my)!=0)
  133. it--;
  134. }
  135. else if(s[j]=='>'){
  136. //cout << *it<<" "<<*--my.end()<<endl;
  137. if(--my.end()!=it)
  138. it++;
  139. }
  140. else if(s[j]=='-'){
  141. if(sz(my)!=0){
  142.  
  143. jj=--it;
  144. my.erase(++it);
  145. it=jj;
  146.  
  147. }
  148. }
  149. else{
  150.  
  151. if(sz(my)==0){
  152. my.pb(s[j]);
  153. it++;
  154. }
  155. else{
  156. jj=it;
  157. my.insert(++jj,s[j]);
  158. it++;
  159.  
  160.  
  161. }
  162. }
  163.  
  164.  
  165. }
  166. tr(my,ll)
  167. cout << *ll;
  168. cout <<endl;
  169.  
  170. }
  171.  
  172. // t1 = clock() - t1;
  173. // double time_taken = ((double)t1)/CLOCKS_PER_SEC; // in seconds
  174. // printf("program take %f seconds to execute \n", time_taken);
  175. return 0;
  176. }
  177.  
Success #stdin #stdout 0s 3476KB
stdin
2
<<BP<A>>Cd-
ThIsIsS3Cr3t
stdout
BAPC
ThIsIsS3Cr3t