Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <set>
- #include <vector>
- #include <string>
- #include <stack>
- using namespace std;
- #define pb push_back
- #define mp pake_pair
- struct tag
- {
- string ss;
- bool open;//1 - da, 0 - net
- tag(){}
- tag(string _ss, bool _open)
- {
- ss = _ss;
- open = _open;
- }
- };
- bool chek(string st)
- {
- vector<tag>v;
- stack<tag>tags;
- if (st[0] != '<') {return 0;}
- if (st[st.size()-1] != '>') {return 0;}
- for (int i = 0; i < st.size()-1; i++)
- {
- if (st[i] == '<')
- {
- int k = i+1;
- bool zakr = 0;
- if (st[k] == '/')
- {
- zakr = 1;
- k++;
- }
- else
- if (st[k] <= 'a' && st[k] >= 'z')
- {return 0;}
- int kollet = 0;
- string tmp = "";
- while (st[k] >= 'a' && st[k] <= 'z' && k < st.size())
- {
- kollet++;
- tmp += st[k];
- k++;
- }
- if (kollet == 0)
- { return 0;}
- if (st[k] != '>') {return 0;}
- if (k+1 < st.size() && st[k + 1] != '<') {return 0;}
- i = k;
- if (zakr)
- v.pb(tag(tmp,0));
- else
- v.pb(tag(tmp,1));
- }
- }
- for (int i = 0; i < v.size(); i++)
- {
- if (v[i].open)
- tags.push(v[i]);
- else
- {
- if (tags.empty()){return 0;}
- if (v[i].ss == tags.top().ss)
- tags.pop();
- else
- {return 0;}
- }
- }
- if (!tags.empty()){return 0;}
- return 1;
- }
- int main()
- {
- freopen("xml.in", "r", stdin);
- freopen("xml.out", "w", stdout);
- string stri;
- cin >> stri;
- string s = stri;
- int i = 0, j = 0;
- while (i < stri.size())
- {
- s = stri;
- for (j = 0; j < 26; j++){
- s[i] =char(j+'a');
- if (chek(s) == 1)
- {
- cout << s;
- return 0;
- }
- }
- s[i] = '<';
- if (chek(s))
- {
- cout << s;
- return 0;
- }
- s[i] = '>';
- if (chek(s))
- {
- cout << s;
- return 0;
- }
- s[i] = '/';
- if (chek(s))
- {
- cout << s;
- return 0;
- }
- i++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement