A. Gotta Catch Em' All! (map的使用)

vj链接:

18暑假热身训练2-F

题意:

给你一个字符串,问里面的字符可以最多组成多少个Bulbasaur。

思路:

找该字符串中最少的Bulbasaur中的字母个数即为所求。

注意:

map数组清空写法为m.clear();

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<map>
 5 #include<algorithm>
 6 using namespace std;
 7 map<char,int>m;
 8 char c[7]={'B','u','l','b','a','s','r'};
 9 int num[7]={1,2,1,1,2,1,1};
10 char s[100010];
11 int main()
12 {
13     while(~scanf("%s",s))
14     {
15         m.clear();
16         int len=strlen(s);
17         for(int i=0;i<len;i++)
18         {
19             m[s[i]]++;
20         }
21         int ans=0x3f3f3f3f;
22         for(int i=0;i<7;i++)
23         {
24             ans=min(ans,m[c[i]]/num[i]);
25         }
26     
27         cout<<ans<<endl;
28         memset(s,'',sizeof(s));
29      
30     }
31 return 0;
32 } 
原文地址:https://www.cnblogs.com/1013star/p/9287998.html