Codeforces Round #239 (Div. 2), problem: (B) Garland editorial: http://codeforces.com/blog/entry/11333
Codeforces Round #239 (Div. 2), problem: (B) Garland solution: http://ideone.com/2Ls7nn
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int main() { int a[50], b[50], cnt, flag; char s1[1005], s2[1005]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); cnt=flag=0; scanf("%s%s", s1, s2); for(int i=0; i<strlen(s1); i++) a[s1[i]-97]++; for(int i=0; i<strlen(s2); i++) b[s2[i]-97]++; for(int i=0; i<50; i++) { cnt+=min(a[i], b[i]); if(a[i]==0 && b[i]>0) { flag=1; break; } } if(flag) printf("-1"); else printf("%d", cnt); return 0; }
No comments:
Post a Comment