-
Notifications
You must be signed in to change notification settings - Fork 52
/
408B. Garland.cpp
55 lines (46 loc) · 872 Bytes
/
408B. Garland.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
//============================================================================
//problem link:http://codeforces.com/contest/408/problem/B
// Name : .cpp
// Author : mohand sakr
// Version :
// Copyright : use it under your responsibility
// Description : Hello World in C++, Ansi-style
//status:accepted
//============================================================================
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
int arr[26];
int arr2[26];
int main() {
string s,s2;
int sum=0;
cin>>s>>s2;
int len1=s.length();
int len2=s2.length();
for(int i=0;i<len1;i++){
++arr[s[i]-'a'];
}
for(int i=0;i<len2;i++){
++arr2[s2[i]-'a'];
}
for(int i=0;i<26;i++){
if(arr2[i])
{
if(arr[i])
sum+=min(arr[i],arr2[i]);
else{
sum=0;
break;
}
}
}
if(sum){
cout<<sum;
}
else{
cout<<"-1";
}
return 0;
}