Guest User

Untitled

a guest
Oct 16th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <stack>
  5.  
  6. #define pb push_back
  7. using namespace std;
  8. vector <string> a,b;
  9. bool parse(string s)
  10. {
  11.     a.clear();
  12.     b.clear();
  13.     int n=s.size();
  14.     if(s[0]!='<' && s[n-1]!='>')
  15.         return false;
  16.     for(int i=0; i<n; i++)
  17.     {
  18.         string t;
  19.         if(s[i]=='>')return false;
  20.         if(s[i]=='<')
  21.         {
  22.             i++;
  23.             while(s[i]!='>')
  24.             {
  25.                 if(s[i]=='<')return false;
  26.                 t+=s[i];
  27.                 i++;
  28.             }
  29.             a.pb(t);
  30.         }
  31.     }
  32.     if(a.empty())
  33.     {
  34.         return false;
  35.     }
  36.     for(int i=0; i<a.size(); i++)
  37.     {
  38.         if (a[i]=="")return  false;
  39.     }
  40.     return true;
  41. }
  42. bool is_pr(vector<string> a)
  43. {
  44.     stack <string> st;
  45.     if(a[0][0]!='/')
  46.         st.push(a[0]);
  47.     else return 0;
  48.     for(int i=1; i<a.size(); i++)
  49.     {
  50.         if(a[i][0]!='/')
  51.         {
  52.             st.push(a[i]);
  53.         }
  54.         else
  55.         {
  56.             if(!st.empty())
  57.             {
  58.                 string t=a[i];
  59.                 t.erase(t.begin());
  60.                 if (t==st.top())
  61.                 {
  62.                     st.pop();
  63.                 }
  64.             }
  65.             else return 0;
  66.         }
  67.     }
  68.     if(st.size()!=0)return false;
  69.     return true;
  70. }
  71. int main()
  72. {
  73.     freopen("xml.in","r",stdin);
  74.     freopen("xml.out","w",stdout);
  75.     string s,v="qwertyuiopasdfghjklzxcvbnm<>/";
  76.     cin>>s;
  77.     int n=s.size(),n1=v.size();
  78.     for(int i=0; i<n; i++)
  79.     {
  80.         string ans=s;
  81.         for(int j=0; j<n1; j++)
  82.         {
  83.             ans[i]=v[j];
  84.  
  85.             if(parse(ans))
  86.             {
  87.                 if(is_pr(a))
  88.                 {
  89.                     cout<<ans;
  90.                     return 0;
  91.                 }
  92.             }
  93.         }
  94.     }
  95.     return 0;
  96. }
Add Comment
Please, Sign In to add comment