View Code of Problem 22

#include<bits/stdc++.h>
using namespace std;

int main(void)
{
  int i,j,flag;
  vector <int> alpha(26,0);
  string s1,s2;
  while(cin>>s1>>s2)
  {
    i=0;j=0;flag=0;
    while(i<s1.size()&&flag<s2.size())
    {
      if(s1[i]==s2[flag])
      {alpha[s1[i]-'a']=1;++i;++flag;}
      else
      {
        for(j=flag;j<s2.size();++j)
        {
          if(s1[i]==s2[j])
          {flag=j;break;}
          else if(j==s2.size()-1)
            ++i;
        }
      }
    }
    for(i=0;i<26;++i)
    {
      if(alpha[i])
        printf("%c",'a'+i);
      alpha[i]=0;
    }
    cout<<endl;
  }
}

Double click to view unformatted code.


Back to problem 22