fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define fi first
  4. #define se second
  5. #define MASK(i) (1LL << (i))
  6. #define BIT(x, i) (((x) >> (i)) & 1)
  7. #define ALL(v) (v).begin(), (v).end()
  8. #define pb push_back
  9. #define fu(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
  10. #define fd(i, a, b) for (int i = (b), _a = (a); i >= _a; --i)
  11. #define REP(i, n) for (int i = 1, _n = (n); i <= _n; ++i)
  12. #define el cout << "\n"
  13. #define MAX_SIZE 100005
  14. #define LOG 21
  15. #define MOD (ll)(1e9 + 7)
  16. #define INF (ll)(1e15)
  17.  
  18. using namespace std;
  19. mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
  20. mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
  21.  
  22. template <class T1, class T2>
  23. bool maximize(T1 &a, T2 b) {if (a < b){a = b; return true;} return false;}
  24.  
  25. template <class T1, class T2>
  26. bool minimize(T1 &a, T2 b) {if (a > b){a = b; return true;} return false;}
  27.  
  28. template <class T1, class T2>
  29. void add(T1 &a, T2 b) {a += b; if (a >= MOD) a -= MOD;}
  30.  
  31. template <class T1, class T2>
  32. void sub(T1 &a, T2 b) {a -= b; if (a < 0) a += MOD;}
  33.  
  34. template <class T>
  35. void dup_shot(vector <T> &v) {
  36. sort(ALL(v));
  37. v.erase(unique(ALL(v)), (v).end());
  38. }
  39.  
  40. string s;
  41.  
  42. void init() {
  43. getline(cin, s);
  44. }
  45.  
  46. void run() {
  47. int lastspace = 0;
  48. for (int i = 0; i < (int)s.size(); i++) {
  49. if (s[i] == ' ') maximize(lastspace, i);
  50. }
  51.  
  52. int idx = 0;
  53. while (idx < (int)s.size()) {
  54. if (s[idx] == ' ') {
  55. ++idx; break;
  56. }
  57. cout << s[idx++];
  58. } el;
  59.  
  60. while (idx < lastspace) {
  61. cout << s[idx++];
  62. } el;
  63.  
  64. ++idx;
  65. while (idx < (int)s.size()) {
  66. cout << s[idx++];
  67. }
  68. }
  69.  
  70. int main() {
  71. ios::sync_with_stdio(0);
  72. cin.tie(0); cout.tie(0);
  73. init();
  74. clock_t start = clock();
  75. run();
  76. cerr << "\nTime run: " << clock() - start << " ms!\n";
  77.  
  78. return 0;
  79. }
  80.  
Success #stdin #stdout #stderr 0s 5288KB
stdin
Standard input is empty
stdout

stderr
Time run: 256 ms!