Advertisement
agul

ITMO IO 20120526 (Basic) :: Problem A

May 27th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.38 KB | None | 0 0
  1. #pragma comment(linker, "/STACK:66777216")
  2. #define _USE_MATH_DEFINES
  3. #define _CRT_SECURE_NO_WARNINGS
  4. #include <vector>
  5. #include <list>
  6. #include <map>
  7. #include <set>
  8. #include <deque>
  9. #include <stack>
  10. #include <bitset>
  11. #include <algorithm>
  12. #include <functional>
  13. #include <numeric>
  14. #include <utility>
  15. #include <sstream>
  16. #include <iostream>
  17. #include <iomanip>
  18. #include <cstdio>
  19. #include <cmath>
  20. #include <cstdlib>
  21. #include <ctime>
  22. #include <queue>
  23. #include <assert.h>
  24. #include <memory.h>
  25. #pragma hdrstop
  26.  
  27. using namespace std;
  28.  
  29. #define pb push_back
  30. #define mp make_pair
  31. #define X first
  32. #define Y second
  33. #define y0 __MY_Y0__
  34. #define y1 __MY_Y1__
  35. #define sz(a) (int)a.size()
  36. #define fill(a, x) memset (a, x, sizeof(a))
  37.  
  38. #ifdef _DEBUG
  39.     #define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
  40.     #define E(x) {cout << "# " << #x << " = " << (x) << " ";}
  41.     #define Ou(x) {cout << "# " << (x) << endl;}
  42.     #define OK {cout << "# OK    Line : " << __LINE__ << endl;}
  43. #else
  44.     #define Eo(x)
  45.     #define E(x)
  46.     #define Ou(x)
  47.     #define OK
  48. #endif
  49.  
  50. #ifdef WIN32
  51.     #define LLD "%I64d"
  52. #else
  53.     #define LLD "%lld"
  54. #endif
  55.  
  56. typedef long long ll;
  57. typedef unsigned long long ull;
  58. typedef pair<int, int> pii;
  59.  
  60. inline void sIO() {
  61. #ifdef _DEBUG
  62.     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
  63. #endif
  64. }
  65. inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
  66. inline void fIO(string fn) {
  67. #ifdef _DEBUG
  68.     freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
  69. #else
  70.     freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
  71. #endif
  72. }
  73. inline void TM() {
  74. #ifdef _DEBUG
  75.     cout << endl << "# Time: " << clock() / 1000. << endl;
  76. #endif
  77. }
  78. template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
  79. template<class T> inline T sqr(T x) {return x * x;}
  80. template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
  81. template<class T> inline T lcm(T a, T b) {return a * b / gcd(a, b);}
  82. template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
  83. template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
  84. template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
  85. inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
  86. inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
  87. inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
  88. inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
  89. inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
  90. inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
  91. inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
  92. inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
  93. inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
  94. inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
  95. inline int dig(char ch) {return ch - 48;}
  96. inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
  97. inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
  98. inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
  99. inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}
  100.  
  101. const int INF = 0x3f3f3f3f;
  102. const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
  103. const double EPS = 1e-9;
  104. const int MD = 1000000007;
  105.  
  106. int ls, x, ch, cur[222222], kk;
  107. string s;
  108. vector<int> wh[256];
  109.  
  110. int main() {
  111.     fIO("backup");
  112.     cin.sync_with_stdio(0);
  113.     cin >> s;
  114.     ls = s.length();
  115.     x = 0;
  116.     for (int i = 0; i < ls; ++i) {
  117.         ch = s[i];
  118.         kk = sz(wh[ch]);
  119.         if (kk && wh[ch][kk - 1] < x - 1) {
  120.             for (int j = wh[ch][kk - 1] + 1; j < x; ++j) {
  121.                 putchar(cur[j]);
  122.                 wh[cur[j]].pop_back();
  123.             }
  124.             putchar('\n');
  125.             x = wh[ch][kk - 1] + 1;
  126.         }
  127.         cur[x] = ch;
  128.         wh[ch].pb(x++);
  129.     }
  130.     for (int i = 0; i < x; ++i)
  131.         putchar(cur[i]);
  132.     putchar('\n');
  133.     return 0;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement