Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3. #include <algorithm>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. void write(stack <char> s)
  9. {
  10. stack <char> news = s;
  11. while (!news.empty())
  12. {
  13. cout << news.top() << " ";
  14. news.pop();
  15. }
  16. cout << endl;
  17. }
  18.  
  19. int main() {
  20. //ifstream cin("input.txt");
  21. //ofstream cout("output.txt");
  22.  
  23. string str1, str2;
  24. cin >> str1 >> str2;
  25. int length = str1.length();
  26. stack <char> s;
  27. int i1 = 0;
  28.  
  29. for (int i = 0; i < length; i++) {
  30. write(s);
  31. char c = str2[i];
  32. if (c != str1[i1] && s.empty()) {
  33. while (c != str1[i1] && i1 < length) {
  34. s.push(str1[i1]);
  35. i1++;
  36. }
  37. if (i1 == length) {
  38. cout << "NO" ;
  39. return 0;
  40. }
  41. }
  42. else
  43. if (c != str1[i1] && !s.empty()) {
  44. if (c == s.top()) {
  45. s.pop();
  46. }
  47. else {
  48. cout << "NO" ;
  49. return 0;
  50. }
  51. }
  52. else
  53. if (c == str1[i1] && s.empty()) {
  54. i1++;
  55. }
  56. else
  57. if (c == str1[i1] && !s.empty()) {
  58. cout << "NO";
  59. return 0;
  60. }
  61. }
  62.  
  63. cout << "YES" ;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement