-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLittleElephantAndString.cpp
72 lines (68 loc) · 1.25 KB
/
LittleElephantAndString.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
using namespace std;
struct LittleElephantAndString
{
int getNumber(string A, string B)
{
int ret;
int i,j,k,flag=0;
string s=B;
for(i=0; i<A.size(); i++)
{
k=0;
for(j=0; j<s.size(); j++)
{
if(A[i]==s[j])
{
k=1;
s[j]='#';
break;
}
}
if(k==0)
{
flag=1;
break;
}
}
if(flag)
ret=-1;
else
{
k=0;
j=A.size()-1;
for(i=A.size()-1;i>=0;i--)
if(A[i]==B[j])
{
k++;
j--;
}
ret=A.size()-k;
}
return ret;
}
};
// BEGIN CUT HERE
int main()
{
string s,s1;
cin>>s;
cin>>s1;
int j=LittleElephantAndString().getNumber(s,s1);
cout<<j;
}
// END CUT HERE