题目:https://vijos.org/p/1902
题解:sb题。。。扫一遍每个字母出现的次数即可
代码:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set> 10 #include<queue> 11 #include<string> 12 #define inf 1000000000 13 #define maxn 500+100 14 #define maxm 500+100 15 #define eps 1e-10 16 #define ll long long 17 #define pa pair<int,int> 18 #define for0(i,n) for(int i=0;i<=(n);i++) 19 #define for1(i,n) for(int i=1;i<=(n);i++) 20 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 21 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 22 #define mod 1000000007 23 using namespace std; 24 inline int read() 25 { 26 int x=0,f=1;char ch=getchar(); 27 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} 28 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();} 29 return x*f; 30 } 31 int n,m,a[1000],b[100]; 32 string st,s; 33 int main() 34 { 35 freopen("input.txt","r",stdin); 36 freopen("output2.txt","w",stdout); 37 int cs=read(),mm=0; 38 s="good morning";n=s.length(); 39 memset(b,0,sizeof(b)); 40 for0(i,n-1)b[s[i]-‘ ‘+1]++; 41 while(cs--) 42 { 43 getline(cin,st); 44 m=st.length(); 45 memset(a,0,sizeof(a)); 46 for0(i,m-1)a[st[i]-‘ ‘+1]++; 47 int ans=inf; 48 for0(i,n-1)ans=min(ans,a[s[i]-‘ ‘+1]/b[s[i]-‘ ‘+1]); 49 printf("Case #%d: %d\n",++mm,ans); 50 } 51 return 0; 52 }
时间: 2024-11-05 15:55:50