Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- void write(stack <char> s)
- {
- stack <char> news = s;
- while (!news.empty())
- {
- cout << news.top() << " ";
- news.pop();
- }
- cout << endl;
- }
- int main() {
- //ifstream cin("input.txt");
- //ofstream cout("output.txt");
- string str1, str2;
- cin >> str1 >> str2;
- int length = str1.length();
- stack <char> s;
- int i1 = 0;
- for (int i = 0; i < length; i++) {
- write(s);
- char c = str2[i];
- if (c != str1[i1] && s.empty()) {
- while (c != str1[i1] && i1 < length) {
- s.push(str1[i1]);
- i1++;
- }
- if (i1 == length) {
- cout << "NO" ;
- return 0;
- }
- }
- else
- if (c != str1[i1] && !s.empty()) {
- if (c == s.top()) {
- s.pop();
- }
- else {
- cout << "NO" ;
- return 0;
- }
- }
- else
- if (c == str1[i1] && s.empty()) {
- i1++;
- }
- else
- if (c == str1[i1] && !s.empty()) {
- cout << "NO";
- return 0;
- }
- }
- cout << "YES" ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement