Advertisement
Guest User

Untitled

a guest
May 25th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1.  
  2.  
  3. #include "pch.h"
  4. #include <iostream>
  5. #include <sstream>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. struct el {
  11. string a;
  12. el *p = NULL;
  13. }
  14.  
  15. int main() {
  16. string line;
  17. getline(cin, line);
  18.  
  19. stringstream input(line);
  20.  
  21. el *first = new el;
  22. el *cur =  first;
  23.  
  24. el *k = NULL;
  25. el *t = NULL;
  26.  
  27. while (input >> cur->a) {
  28. cur->p = new el;
  29. if (cur->a[0] == 'k' && !k) k = cur;
  30. if (cur->a[0] == 't' && !t) t = cur;
  31. cur = cur->p;
  32. }
  33.  
  34. if (k && t) swap(*k, *t);
  35.  
  36. for (; first->next; first = first->p) {
  37. cout << first->a;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement