Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <stack>
- #define pb push_back
- using namespace std;
- vector <string> a,b;
- bool parse(string s)
- {
- a.clear();
- b.clear();
- int n=s.size();
- if(s[0]!='<' && s[n-1]!='>')
- return false;
- for(int i=0; i<n; i++)
- {
- string t;
- if(s[i]=='>')return false;
- if(s[i]=='<')
- {
- i++;
- while(s[i]!='>')
- {
- if(s[i]=='<')return false;
- t+=s[i];
- i++;
- }
- a.pb(t);
- }
- }
- if(a.empty())
- {
- return false;
- }
- for(int i=0; i<a.size(); i++)
- {
- if (a[i]=="")return false;
- }
- return true;
- }
- bool is_pr(vector<string> a)
- {
- stack <string> st;
- if(a[0][0]!='/')
- st.push(a[0]);
- else return 0;
- for(int i=1; i<a.size(); i++)
- {
- if(a[i][0]!='/')
- {
- st.push(a[i]);
- }
- else
- {
- if(!st.empty())
- {
- string t=a[i];
- t.erase(t.begin());
- if (t==st.top())
- {
- st.pop();
- }
- }
- else return 0;
- }
- }
- if(st.size()!=0)return false;
- return true;
- }
- int main()
- {
- freopen("xml.in","r",stdin);
- freopen("xml.out","w",stdout);
- string s,v="qwertyuiopasdfghjklzxcvbnm<>/";
- cin>>s;
- int n=s.size(),n1=v.size();
- for(int i=0; i<n; i++)
- {
- string ans=s;
- for(int j=0; j<n1; j++)
- {
- ans[i]=v[j];
- if(parse(ans))
- {
- if(is_pr(a))
- {
- cout<<ans;
- return 0;
- }
- }
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment