标签:
题意很简单,需要注意的是(2,5)和(6,9)的处理,直接上代码:
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespace std; 5 6 const int INF = 1 << 29; 7 const int N = 10; 8 const int M = 201; 9 int cnt1[N]; 10 int cnt2[N]; 11 char digit[N]; 12 char str[M]; 13 14 int solve() 15 { 16 memset( cnt1, 0, sizeof(cnt1) ); 17 memset( cnt2, 0, sizeof(cnt2) ); 18 for ( int i = 0; i < strlen(digit); i++ ) 19 { 20 cnt1[digit[i] - ‘0‘]++; 21 } 22 //将(2,5)视为同一个数字然后计算两次 23 cnt1[2] += cnt1[5], cnt1[5] = cnt1[2]; 24 //(6,9)也一样 25 cnt1[6] += cnt1[9], cnt1[9] = cnt1[6]; 26 for ( int i = 0; i < strlen(str); i++ ) 27 { 28 cnt2[str[i] - ‘0‘]++; 29 } 30 cnt2[2] += cnt2[5], cnt2[5] = cnt2[2]; 31 cnt2[6] += cnt2[9], cnt2[9] = cnt2[6]; 32 int ans = INF; 33 for ( int i = 0; i < N; i++ ) 34 { 35 if ( cnt1[i] == 0 ) continue; 36 int tmp = cnt2[i] / cnt1[i]; 37 if ( tmp < ans ) ans = tmp; 38 } 39 return ans; 40 } 41 42 int main () 43 { 44 while ( scanf("%s%s", digit, str) != EOF ) 45 { 46 int ans = solve(); 47 printf("%d\n", ans); 48 } 49 return 0; 50 }
标签:
原文地址:http://www.cnblogs.com/huoxiayu/p/4401673.html