text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
using namespace std;
int num[10] = {0};
int tnum[10] = {0};
int main() {
int t;
cin >> t;
string s;
cin >> s;
for (int i = 0; i < s.size(); ++i) {
int temp = s[i] - '0';
if (temp == 2) num[5]++;
if (temp == 5) num[2]++;
if (temp == 6) num[9]++;
if (temp == 9) num[6]++;
num[temp]++;
}
while (t > 0) {
int temp = t % 10;
if (temp == 2) tnum[5]++;
if (temp == 5) tnum[2]++;
if (temp == 6) tnum[9]++;
if (temp == 9) tnum[6]++;
tnum[temp]++;
t /= 10;
}
int ans = 20000;
for (int i = 0; i < 10; ++i) {
if (tnum[i] == 0) continue;
int temp = num[i] / tnum[i];
if (temp < ans) ans = temp;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int cnt1[10], cnt2[10], ans(1e9);
int main() {
string s, t;
cin >> t >> s;
for (auto ch : s) cnt1[ch - '0']++;
for (auto ch : t) cnt2[ch - '0']++;
cnt1[6] += cnt1[9], cnt2[6] += cnt2[9];
cnt1[2] += cnt1[5], cnt1[5] = 0;
cnt2[2] += cnt2[5], cnt2[5] = 0;
for (int i = 0; i < 8; i++)
if (cnt2[i]) ans = min(cnt1[i] / cnt2[i], ans);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
int i, j, ans = 1000000, s1[10] = {0}, s2[10] = {0};
cin >> a;
for (i = 0; i < a.size(); i++) {
s1[a[i] - '0']++;
}
cin >> b;
for (i = 0; i < b.size(); i++) {
s2[b[i] - '0']++;
}
s1[6] += s1[9];
s1[2] += s1[5];
s2[6] += s2[9];
s2[2] += s2[5];
for (i = 0; i <= 9; i++) {
if (i == 9 || i == 5) continue;
if (s1[i] > 0) ans = min(ans, s2[i] / s1[i]);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
string t;
while (cin >> t) {
int a, num[10] = {0}, have[10] = {0};
string s;
cin >> s;
for (int i = 0; i < t.size(); i++) {
a = t[i] - '0';
if (a == 9)
num[6]++;
else if (a == 5)
num[2]++;
else
num[a]++;
}
int ans = 10000000005;
for (int i = 0; i < s.size(); i++) {
a = s[i] - '0';
if (a == 9)
have[6]++;
else if (a == 5)
have[2]++;
else
have[a]++;
}
for (int i = 0; i < 9; i++) {
if (i == 5) continue;
if (num[i] > 0) ans = min(ans, have[i] / num[i]);
}
printf("%d\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char a[12309], b[12309];
int A[12309], B[12309];
int Answer = 999999999;
int main() {
scanf("%s%s", a, b);
for (int i = 0; a[i]; i++) A[a[i]]++;
for (int i = 0; b[i]; i++) B[b[i]]++;
A['2'] += A['5'];
A['5'] = 0;
A['6'] += A['9'];
A['9'] = 0;
B['2'] += B['5'];
B['5'] = 0;
B['6'] += B['9'];
B['9'] = 0;
for (int i = '0'; i <= '9'; i++)
if (A[i]) Answer = min(Answer, B[i] / A[i]);
cout << Answer << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t;
cin >> t;
string s;
cin >> s;
map<char, long long> m, m1;
for (long long i = 0; i < (long long)s.size(); i++) {
if (s[i] - '0' == 5)
m[2]++;
else if (s[i] - '0' == 9)
m[6]++;
else
m[s[i] - '0']++;
}
long long a[10] = {};
while (t > 0) {
long long c = t % 10;
if (c == 5)
a[2]++;
else if (c == 9)
a[6]++;
else
a[c]++;
t /= 10;
}
long long ans = INT_MAX;
for (long long i = 0; i < 8; i++) {
if (i == 5) continue;
if (a[i] > 0) ans = min(ans, m[i] / a[i]);
}
if (ans == INT_MAX)
cout << 0 << '\n';
else
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string a, b;
cin >> a >> b;
vector<int> A(10), B(10);
for (int i = 0; i < a.size(); ++i) A[a[i] - '0']++;
for (int i = 0; i < b.size(); ++i) B[b[i] - '0']++;
int ans = 1e9;
for (int i = 0; i < 10; ++i) {
if (A[i] == 0) continue;
if (i == 6 || i == 9) {
ans = min(ans, (B[6] + B[9]) / (A[6] + A[9]));
} else if (i == 2 || i == 5) {
ans = min(ans, (B[2] + B[5]) / (A[2] + A[5]));
} else {
ans = min(ans, B[i] / A[i]);
}
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long int mp[10];
memset(mp, 0, sizeof(mp));
for (int i = 0; i <= s.length() - 1; i++) {
if (s[i] == '9') s[i] = '6';
if (s[i] == '5') s[i] = '2';
mp[s[i] - '0']++;
}
string ice;
cin >> ice;
long long int mp2[10];
memset(mp2, 0, sizeof(mp2));
for (int i = 0; i <= ice.length() - 1; i++) {
if (ice[i] == '9') ice[i] = '6';
if (ice[i] == '5') ice[i] = '2';
mp2[ice[i] - '0']++;
}
long long int counti = INT_MAX;
for (int i = 0; i <= 9; i++) {
counti = min((int)counti, (mp[i] == 0) ? INT_MAX : (int)(mp2[i] / mp[i]));
}
cout << counti << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int NA(int x) {
if (x == 5) return 2;
if (x == 9) return 6;
return x;
}
int YN(vector<int> x, vector<int> y) {
int i, N = x.size();
for (i = 0; i < N; i++)
if (x[i] > y[i]) return 0;
return 1;
}
int main(int argc, char *argv[]) {
int t, ans = 0, i, j;
cin >> t;
vector<int> c(9, 0), C(9, 0);
while (t) {
c[NA(t % 10)]++;
t /= 10;
}
string S;
cin >> S;
for (i = 0; i < S.size(); ++i) {
int d = NA(S[i] - '0');
C[d]++;
if (!YN(c, C)) continue;
ans++;
for (j = 0; j < 9; j++) C[j] -= c[j];
}
cout << ans;
return EXIT_SUCCESS;
}
|
#include <bits/stdc++.h>
using namespace std;
inline bool check(int x[], int y[]) {
for (int i = 0; i < 10; i++) {
if (y[i] < x[i]) {
int diff = x[i] - y[i];
y[i] = 0;
if (i == 2 && y[5] >= diff) {
y[5] -= diff;
} else if (i == 5 && y[2] >= diff) {
y[2] -= diff;
} else if (i == 6 && y[9] >= diff) {
y[9] -= diff;
} else if (i == 9 && y[6] >= diff) {
y[6] -= diff;
} else {
return false;
}
} else {
y[i] -= x[i];
}
}
return true;
}
int main() {
string t, str;
cin >> t >> str;
int tarr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int strarr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
for (int i = 0; i < t.length(); i++) tarr[t[i] - '0']++;
for (int i = 0; i < str.length(); i++) strarr[str[i] - '0']++;
int ans = 0;
while (check(tarr, strarr)) ans++;
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
inline void gmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
if (b < a) a = b;
}
using namespace std;
const int N = 1e3 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647,
ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567,
ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
void fre() {
freopen("/Users/luras/Desktop/in.txt", "r", stdin);
freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const double INF = 1e9;
int casenum, casei;
int a[30], b[30], ans;
int len1, len2;
char s1[300], s2[300];
int main() {
while (~scanf("%s%s", s1, s2)) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
len1 = strlen(s1);
len2 = strlen(s2);
for (int i = 0; i < len1; i++) {
a[s1[i] - '0']++;
}
a[2] += a[5];
a[6] += a[9];
a[5] = a[9] = 0;
for (int i = 0; i < len2; i++) {
b[s2[i] - '0']++;
}
b[2] += b[5];
b[6] += b[9];
b[5] = b[9] = 0;
ans = INF;
for (int i = 0; i <= 9; i++) {
if (a[i]) gmin(ans, b[i] / a[i]);
}
printf("%d\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int type(int n) {
switch (n) {
case 0:
return 0;
case 1:
return 1;
case 2:
case 5:
return 2;
case 3:
return 3;
case 4:
return 4;
case 6:
case 9:
return 5;
case 7:
return 6;
case 8:
return 7;
default:
assert(false);
}
}
int type(char c) { return type(c - '0'); }
int main() {
string t;
cin >> t;
int countT[8];
for (int i = 0; i < 8; i++) countT[i] = 0;
for (int i = 0; i < t.length(); i++) countT[type(t[i])]++;
string s;
cin >> s;
int countS[8];
for (int i = 0; i < 8; i++) countS[i] = 0;
for (int i = 0; i < s.length(); i++) countS[type(s[i])]++;
int result = 10000000;
for (int i = 0; i < 8; i++) {
if (countT[i] != 0) {
result = min(result, countS[i] / countT[i]);
}
}
cout << result;
return 0;
}
|
#include <bits/stdc++.h>
int main(void) {
char z[201], *p;
const int H[] = {0, 1, 2, 3, 4, 2, 6, 7, 5, 6};
int s = 999, n = 2, Q[2][8] = {};
while (n--)
for (gets(p = z); *p; ++Q[n][H[*p++ - '0']])
;
while (s && 8 ^ ++n)
if (Q[1][n]) s = std::min(s, Q[0][n] / Q[1][n]);
printf("%d", s);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int v[11000];
int main(void) {
char s[11000];
char ss[11000];
scanf("%s\n%s", s, ss);
int Len = strlen(ss);
for (int i = 0; i < Len; i++) {
if (ss[i] == '5')
ss[i] = '2';
else if (ss[i] == '9')
ss[i] = '6';
v[ss[i] - '0']++;
}
int res = 0, flag = 1;
Len = strlen(s);
while (flag) {
for (int i = 0; i < Len; i++) {
if (s[i] == '5')
s[i] = '2';
else if (s[i] == '9')
s[i] = '6';
if (v[s[i] - '0'] == 0) {
flag = false;
break;
} else
v[s[i] - '0']--;
}
if (flag) res++;
}
cout << res << "\n";
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")
#pragma GCC optimize("trapv")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " : " << a << endl;
err(++it, args...);
}
long long int gcd(long long int a, long long int b) {
while (b) {
long long int c = b;
b = a % b;
a = c;
}
return a;
}
long long int lcm(long long int a, long long int b) {
if (!a || !b) return 0;
return a * b / gcd(a, b);
}
int main() {
int foo;
cin >> foo;
int aux = foo;
map<int, int> go;
while (aux > 0) {
int di = aux % 10;
aux /= 10;
if (di == 5)
go[2]++;
else if (di == 9)
go[6]++;
else
go[di]++;
}
string s;
cin >> s;
map<int, int> m;
for (long long int i = 0; i < ((s).size()); ++i) {
int num = s[i] - '0';
if (num == 5)
m[2]++;
else if (num == 9)
m[6]++;
else
m[num]++;
}
int mini = 1e9;
for (auto x : go) {
int nume = x.first, ocur = x.second;
mini = min(mini, m[nume] / ocur);
}
cout << mini << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
void checkMin(T& r, T val) {
if (r > val) r = val;
}
vector<int> v;
int d[10];
int d2[10];
bool vis[1000010];
char buf[210];
char sn[10];
int n;
int ans;
void check() {
int res = 0;
for (int i = 0; i < 10; ++i) {
if (v[i] > d[i]) return;
int t = v[i];
while (t--) {
res = res * 11 + (1 + i);
}
}
if (vis[res]) return;
vis[res] = true;
ans++;
}
void dfs(int dep) {
if (dep == n) {
check();
return;
}
if (sn[dep] == '2' || sn[dep] == '5') {
v[2]++;
dfs(dep + 1);
v[2]--;
v[5]++;
dfs(dep + 1);
v[5]--;
} else if (sn[dep] == '6' || sn[dep] == '9') {
v[6]++;
dfs(dep + 1);
v[6]--;
v[9]++;
dfs(dep + 1);
v[9]--;
} else {
v[sn[dep] - '0']++;
dfs(dep + 1);
v[sn[dep] - '0']--;
}
}
int main() {
v = vector<int>(10, 0);
scanf("%s%s", sn, buf);
n = strlen(sn);
int len = strlen(buf);
for (int i = 0; i < len; ++i) d[buf[i] - '0']++;
for (int i = 0; i < n; ++i) d2[sn[i] - '0']++;
int ans = 1 << 30;
if (d2[2] + d2[5]) checkMin(ans, (d[2] + d[5]) / (d2[2] + d2[5]));
if (d2[6] + d2[9]) checkMin(ans, (d[6] + d[9]) / (d2[6] + d2[9]));
if (d2[0]) checkMin(ans, d[0] / d2[0]);
if (d2[1]) checkMin(ans, d[1] / d2[1]);
if (d2[3]) checkMin(ans, d[3] / d2[3]);
if (d2[4]) checkMin(ans, d[4] / d2[4]);
if (d2[7]) checkMin(ans, d[7] / d2[7]);
if (d2[8]) checkMin(ans, d[8] / d2[8]);
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string t, a;
int min = -1, i, Have[10] = {0}, Needed[10] = {0};
cin >> t >> a;
for (i = 0; i < a.length(); i++) {
if (a[i] == '9')
Have[6]++;
else if (a[i] == '5')
Have[2]++;
else
Have[a[i] - 48]++;
}
for (i = 0; i < t.length(); i++) {
if (t[i] == '9')
Needed[6]++;
else if (t[i] == '5')
Needed[2]++;
else
Needed[t[i] - 48]++;
}
for (i = 0; i < 9; i++) {
if (i == 5 || !Needed[i]) continue;
if (min == -1 || Have[i] / Needed[i] < min) min = Have[i] / Needed[i];
}
cout << min << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[15], b[15];
char s[205];
int main() {
int t;
cin >> t >> s;
while (t) {
a[t % 10]++;
t /= 10;
}
int len = strlen(s);
for (int i = 0; i < len; ++i) ++b[s[i] - '0'];
a[2] += a[5];
a[5] = 0;
b[2] += b[5];
a[6] += a[9];
a[9] = 0;
b[6] += b[9];
int ans = 0x3f3f3f3f;
for (int i = 0; i < 10; ++i)
if (a[i]) ans = min(ans, b[i] / a[i]);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int counter[10];
memset(counter, 0, sizeof counter);
string t;
cin >> t;
for (int i = 0; i < t.size(); i++) {
t[i] -= '0';
counter[t[i]]++;
}
string s;
cin >> s;
counter[2] += counter[5];
counter[5] = 0;
counter[6] += counter[9];
counter[9] = 0;
int cnt[10];
memset(cnt, 0, sizeof cnt);
for (int i = 0; i < s.length(); i++) {
s[i] -= '0';
cnt[s[i]]++;
}
cnt[2] += cnt[5];
cnt[6] += cnt[9];
cnt[9] = 0;
cnt[5] = 0;
int ans = 400000;
set<int> st;
for (int i = 0; i < 10; i++) {
if (counter[i]) {
st.insert(cnt[i] / counter[i]);
}
}
cout << *st.begin();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 222;
char s[MaxN], t[MaxN];
int cnts[11], cntt[11];
int main(void) {
int i;
scanf(" %s %s", t, s);
for (i = 0; i < strlen(t); i++) cntt[t[i] - '0']++;
for (i = 0; i < strlen(s); i++) cnts[s[i] - '0']++;
cntt[2] += cntt[5];
cntt[5] = 0;
cntt[6] += cntt[9];
cntt[9] = 0;
cnts[2] += cnts[5];
cnts[5] = 0;
cnts[6] += cnts[9];
cnts[9] = 0;
int res = 222;
for (i = 0; i < 10; i++)
if (cntt[i] > 0) res = min(res, cnts[i] / cntt[i]);
printf("%d\n", res);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int cnt[20];
int main() {
string a, b;
cin >> a >> b;
int sz = b.size();
for (int i = 0; i < sz; i++) {
if (b[i] == '2' || b[i] == '5')
cnt[12]++;
else if (b[i] == '6' || b[i] == '9')
cnt[16]++;
else
cnt[b[i] - '0']++;
}
sz = a.size();
int cn = 0;
while (true) {
for (int i = 0; i < sz; i++) {
if (a[i] - '0' == 2 || a[i] - '0' == 5) {
if (cnt[12])
cnt[12]--;
else
goto res;
} else if (a[i] - '0' == 6 || a[i] - '0' == 9) {
if (cnt[16])
cnt[16]--;
else
goto res;
} else {
if (cnt[a[i] - '0'])
cnt[a[i] - '0']--;
else
goto res;
}
}
cn++;
}
res:
cout << cn << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const double epsilon = 1e-7;
void add(int &A, int B, int MOD) { A = (A + B) % MOD; }
int T;
vector<int> fr(10, 0), need(10, 0);
int main() {
int lg, i, minn = INT_MAX, maxx;
string S;
cin >> T >> S;
lg = S.length();
for (auto x : S) {
++fr[x - '0'];
}
fr[2] = fr[5] = fr[2] + fr[5];
fr[6] = fr[9] = fr[6] + fr[9];
do {
++need[T % 10];
T /= 10;
} while (T);
for (i = 0; i < 10; ++i) {
if (need[i] && i != 5 && i != 2 && i != 6 && i != 9) {
minn = min(minn, fr[i] / need[i]);
}
}
if (need[2] || need[5]) {
maxx = 0;
for (i = 0; i <= fr[2]; ++i) {
int val = INT_MAX;
if (need[2]) {
if (i) {
val = i / need[2];
} else
val = 0;
}
if (need[5]) {
if (fr[2] - i) {
val = min(val, (fr[2] - i) / need[5]);
} else
val = 0;
}
if (val != INT_MAX) {
maxx = max(maxx, val);
}
}
minn = min(minn, maxx);
}
if (need[6] || need[9]) {
maxx = 0;
for (i = 0; i <= fr[6]; ++i) {
int val = INT_MAX;
if (need[6]) {
if (i) {
val = i / need[6];
} else
val = 0;
}
if (need[9]) {
if (fr[6] - i) {
val = min(val, (fr[6] - i) / need[9]);
} else
val = 0;
}
if (val != INT_MAX) {
maxx = max(maxx, val);
}
}
minn = min(minn, maxx);
}
printf("%d", minn);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int t, num[12], fnum[12], ans, i;
char c[1200];
int main() {
scanf("%d", &t);
scanf("%s", c + 1);
for (i = strlen(c + 1); i >= 1; --i) num[c[i] - 48]++;
for (; t; t /= 10) fnum[t % 10]++;
ans = 10000000;
for (i = 0; i <= 9; ++i)
if (i != 2 && i != 5 && i != 6 && i != 9 && fnum[i])
ans = min(ans, num[i] / fnum[i]);
if (fnum[6] + fnum[9])
ans = min(ans, (num[6] + num[9]) / (fnum[6] + fnum[9]));
if (fnum[2] + fnum[5])
ans = min(ans, (num[2] + num[5]) / (fnum[2] + fnum[5]));
printf("%d\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
int sw(char x) {
switch (x) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 2;
case '6':
return 5;
case '7':
return 6;
case '8':
return 7;
case '9':
return 5;
default:
return -1;
}
}
int a[8], b[8];
int main() {
std::ios::sync_with_stdio(false);
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
string s1, s2;
int ans = 1000000;
cin >> s1 >> s2;
for (int i = 0; i < (int)s1.size(); ++i) ++a[sw(s1[i])];
for (int i = 0; i < (int)s2.size(); ++i) ++b[sw(s2[i])];
for (int i = 0; i < 8; ++i) {
if (a[i]) ans = min(ans, b[i] / a[i]);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char str[210], in[10];
int cnt[10], r[10];
int main() {
scanf("%s %s", in, str);
int l = strlen(in);
for (int i = 0; i < l; i++) {
if (in[i] == '9')
cnt[6]++;
else if (in[i] == '5')
cnt[2]++;
else
cnt[in[i] - '0']++;
}
l = strlen(str);
for (int i = 0; i < l; i++) {
if (str[i] == '9')
r[6]++;
else if (str[i] == '5')
r[2]++;
else
r[str[i] - '0']++;
}
int ans = 0x7fffffff;
for (int i = 0; i <= 9; i++) {
if (cnt[i] == 0) continue;
ans = min(ans, r[i] / cnt[i]);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
char t[10];
char s[300];
int num_need[256];
int num_have[256];
int min(int a, int b) {
if (a < b) return a;
return b;
}
int main() {
int i;
scanf("%s %s", t, s);
for (i = 0; t[i]; i++) num_need[t[i]]++;
for (i = 0; s[i]; i++) num_have[s[i]]++;
num_need['6'] += num_need['9'];
num_need['9'] = 0;
num_need['2'] += num_need['5'];
num_need['5'] = 0;
num_have['6'] += num_have['9'];
num_have['9'] = 0;
num_have['2'] += num_have['5'];
num_have['5'] = 0;
int res = 2000000000;
for (i = 0; i < 256; i++)
if (num_need[i]) res = min(res, num_have[i] / num_need[i]);
printf("%d\n", res);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string t;
string values;
static int needs[10] = {0};
static int has[10] = {0};
cin >> t;
cin >> values;
for (int i = 0; i < t.length(); i++) {
if (t[i] == '9') {
needs[6]++;
continue;
}
if (t[i] == '5') {
needs[2]++;
continue;
}
needs[t[i] - '0']++;
}
for (int i = 0; i < values.length(); i++) {
if (values[i] == '9')
has[6]++;
else if (values[i] == '5')
has[2]++;
else
has[values[i] - '0']++;
}
vector<int> indexes;
int max = 9999999;
int index = 0;
for (int i = 0; i < 10; i++) {
if (needs[i]) {
if (!has[i]) {
cout << 0 << endl;
return 0;
}
if (max > has[i] / needs[i]) max = has[i] / needs[i];
}
}
cout << max << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string t;
int num[10] = {0};
bool is_ok() {
for (int i = 0; i < t.size(); i++) {
if (num[t[i] - '0'] < 1) return 0;
num[t[i] - '0']--;
}
return 1;
}
int main() {
cin >> t;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '9') {
s[i] = '6';
}
if (s[i] == '5') {
s[i] = '2';
}
num[s[i] - '0']++;
}
for (int i = 0; i < t.size(); i++) {
if (t[i] == '9') {
t[i] = '6';
}
if (t[i] == '5') {
t[i] = '2';
}
}
int ans = 0;
while (1) {
if (is_ok())
ans++;
else
break;
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int req[10] = {};
int val[10] = {};
int twofiveNo = 0;
int fivenineNo = 0;
int reqtwofiveNo = 0;
int reqfivenineNo = 0;
for (int i = 0; i < a.length(); i++) {
req[a[i] - '0'] += 1;
}
for (int i = 0; i < b.length(); i++) {
val[b[i] - '0'] += 1;
}
bool check = true;
int ans = 0;
while (check) {
for (int i = 0; i < 10; i++) {
if (req[i] > 0) {
if (i == 2 || i == 5) {
if (val[2] + val[5] >= req[i]) {
val[2] -= req[i];
} else {
cout << ans << endl;
exit(0);
}
} else if (i == 6 || i == 9) {
if (val[6] + val[9] >= req[i]) {
val[6] -= req[i];
} else {
cout << ans << endl;
exit(0);
}
} else if (val[i] >= req[i]) {
val[i] -= req[i];
} else {
cout << ans << endl;
exit(0);
}
}
}
ans += 1;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
int main() {
int t, i, j, k, l, num1[11], a[20], num2[11], res[11], cc, ans;
char sub[10], s[300];
while (~scanf("%d", &t)) {
k = 0, cc = 0;
memset(sub, 0, sizeof(sub));
memset(a, 0, sizeof(a));
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
memset(res, 0, sizeof(res));
while (t > 0) {
sub[k] = t % 10 + '0';
a[k++] = t % 10;
num1[t % 10]++;
t = t / 10;
}
sub[k] = '\0';
getchar();
scanf("%s", s);
l = strlen(s);
for (i = 0; i < l; i++) {
num2[s[i] - '0']++;
}
num1[2] += num1[5], num1[6] += num1[9];
num2[2] += num2[5], num2[6] += num2[9];
for (i = 0; i < k; i++) {
if (a[i] == 5)
res[cc++] = num2[2] / num1[2];
else if (a[i] == 9)
res[cc++] = num2[6] / num1[6];
else
res[cc++] = num2[a[i]] / num1[a[i]];
}
ans = res[0];
for (i = 0; i < cc; i++)
if (ans > res[i]) ans = res[i];
printf("%d\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int freq[10], need[10];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int cnt = 0, ok = 1;
string t, s;
cin >> t >> s;
for (int i = 0; i < s.length(); ++i) {
++freq[s[i] - '0'];
}
while (ok) {
for (int i = 0; i < t.length(); ++i) {
if (t[i] == '2' || t[i] == '5') {
if (freq[2]) {
--freq[2];
continue;
}
if (freq[5]) {
--freq[5];
continue;
}
ok = 0;
break;
} else if (t[i] == '6' || t[i] == '9') {
if (freq[6]) {
--freq[6];
continue;
}
if (freq[9]) {
--freq[9];
continue;
}
ok = 0;
break;
} else if (freq[t[i] - '0']) {
--freq[t[i] - '0'];
} else {
ok = 0;
}
}
if (ok) ++cnt;
}
cout << cnt << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10 + 5;
const int INF = 1000000000;
int num[maxn];
int cost[maxn];
string s;
int main() {
int t;
while (cin >> t >> s) {
int ans = 0;
memset(num, 0, sizeof(num));
for (int i = 0; i < s.length(); i++) {
if (s[i] == '6' || s[i] == '9')
num[6]++;
else if (s[i] == '2' || s[i] == '5')
num[2]++;
else
num[s[i] - '0']++;
}
memset(cost, 0, sizeof(cost));
while (t) {
int tem = t % 10;
if (tem == 9)
cost[6]++;
else if (tem == 5)
cost[2]++;
else
cost[tem]++;
t = t / 10;
}
ans = INF;
for (int i = 0; i <= 9; i++) {
if (cost[i]) ans = min(ans, num[i] / cost[i]);
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int dig[10];
int main() {
memset(dig, 0, sizeof(dig));
int t = 0;
scanf("%d", &t);
int tt = t;
while (tt != 0) {
if (tt % 10 == 9)
dig[6]++;
else if (tt % 10 == 5)
dig[2]++;
else
dig[tt % 10]++;
tt /= 10;
}
char s[300];
scanf("%s", s);
int rec[10] = {0};
for (int i = 0; i < (signed)strlen(s); i++) {
if (s[i] - '0' == 9)
rec[6]++;
else if (s[i] - '0' == 5)
rec[2]++;
else
rec[s[i] - '0']++;
}
int minx = 1 << 30;
for (int i = 0; i < 10; i++) {
if (i == 5 || i == 9 || dig[i] == 0) continue;
if (rec[i] / dig[i] < minx) minx = rec[i] / dig[i];
}
printf("%d\n", minx);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string t;
string s;
map<char, int> mp, mp2;
int main() {
cin >> t;
cin >> s;
for (int i = 0; i < t.size(); i++) {
if (t[i] == '9')
mp['6']++;
else if (t[i] == '5')
mp['2']++;
else
mp[t[i]]++;
}
for (int i = 0; i < s.size(); i++) {
if (s[i] == '9')
mp2['6']++;
else if (s[i] == '5')
mp2['2']++;
else
mp2[s[i]]++;
}
int Ans = 0x3fffffff;
for (int i = 0; i < 10; i++) {
if (i == 5 || i == 9) continue;
if (mp[i + '0'] == 0) continue;
Ans = min(Ans, mp2[i + '0'] / mp[i + '0']);
}
cout << Ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int ans, t, i, n, sum, h;
int cnt[20], need[20];
char s[300];
int main() {
scanf("%d", &t);
for (; t; t /= 10) {
++need[t % 10];
}
scanf("%s", s + 1);
n = strlen(s + 1);
for (i = 1; i <= n; ++i) {
++cnt[s[i] - 48];
}
while (cnt[0] >= need[0] && cnt[1] >= need[1] &&
cnt[2] + cnt[5] >= need[2] + need[5] && cnt[3] >= need[3] &&
cnt[4] >= need[4] && cnt[6] + cnt[9] >= need[6] + need[9] &&
cnt[7] >= need[7] && cnt[8] >= need[8]) {
++ans;
cnt[1] -= need[1];
cnt[3] -= need[3];
cnt[4] -= need[4];
cnt[7] -= need[7];
cnt[8] -= need[8];
sum = need[2] + need[5];
h = min(sum, cnt[2]);
cnt[2] -= h;
sum -= h;
h = min(sum, cnt[5]);
cnt[5] -= h;
sum -= h;
sum = need[6] + need[9];
h = min(sum, cnt[6]);
cnt[6] -= h;
sum -= h;
h = min(sum, cnt[9]);
cnt[9] -= h;
sum -= h;
cnt[0] -= need[0];
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ifstream in("input.txt");
char x[5], y[200];
cin >> x >> y;
int a[10], b[10], i;
fill(a, a + 10, 0);
fill(b, b + 10, 0);
for (i = 0; i < strlen(x); i++) a[x[i] - 48] += 1;
a[2] = a[5] = a[2] + a[5];
a[6] = a[9] = a[6] + a[9];
for (i = 0; i < strlen(y); i++) b[y[i] - 48] += 1;
b[2] = b[5] = b[2] + b[5];
b[6] = b[9] = b[6] + b[9];
int kq = 1 << 30;
for (i = 0; i < 10; i++)
if (a[i] != 0 && b[i] != 0 && b[i] / a[i] < kq) kq = b[i] / a[i];
cout << kq;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[210];
int main() {
string t;
cin >> t;
string x;
cin >> x;
int n = t.length();
int ans = 0;
while (1) {
bool f;
for (int i = 0; i < n; i++) {
f = 0;
int p = x.find(t[i]);
if (p != string::npos)
f = 1;
else {
if (t[i] == '2') {
p = x.find('5');
if (p != string::npos) f = 1;
} else if (t[i] == '5') {
p = x.find('2');
if (p != string::npos) f = 1;
} else if (t[i] == '6') {
p = x.find('9');
if (p != string::npos) f = 1;
} else if (t[i] == '9') {
p = x.find('6');
if (p != string::npos) f = 1;
}
}
if (!f) break;
x = x.substr(0, p) + x.substr(p + 1);
}
if (!f)
break;
else
ans++;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
void task_1256D() {
int N;
cin >> N;
for (int I = 0; I < N; I++) {
int n, k;
string str;
cin >> n >> k >> str;
str = str + "1";
while (k > 0) {
int f1 = -1, f0 = -1, s1 = -1;
for (int i = 0; i < n + 1; i++) {
if (f1 < 0) {
if (str[i] == '1') {
f1 = i;
}
} else if (f0 < 0) {
if (str[i] == '0') {
f0 = i;
}
} else if (s1 < 0) {
if (str[i] == '1') {
s1 = i;
}
} else {
break;
}
}
if (s1 < 0) {
break;
}
int len = f0 - f1, dist = s1 - f0, delta = 0;
int cost = len * dist;
if (k < cost) {
if (k > len) {
dist = k / len;
cost = len * dist;
} else {
delta = len - k;
f1 += delta;
len = k;
dist = 1;
cost = len;
}
}
if (len <= dist) {
for (int i = f1 + len - 1; i >= f1; i--) {
str[i] = '0';
str[i + dist] = '1';
}
} else {
for (int i = f1 + dist - 1; i >= f1; i--) {
str[i] = '0';
str[i + len] = '1';
}
}
k -= cost;
}
for (int i = 0; i < n; i++) {
cout << str[i];
}
cout << endl;
}
}
void task_328B() {
string t, ds;
cin >> t >> ds;
int T[10], Ds[10];
for (int i = 0; i < 10; i++) {
T[i] = 0;
Ds[i] = 0;
}
for (int i = 0; i < t.length(); i++) {
T[t[i] - '0']++;
}
for (int i = 0; i < ds.length(); i++) {
Ds[ds[i] - '0']++;
}
T[6] += T[9];
T[9] = 0;
T[2] += T[5];
T[5] = 0;
Ds[6] += Ds[9];
Ds[9] = 0;
Ds[2] += Ds[5];
Ds[5] = 0;
int m = 201;
for (int i = 0; i < 10; i++) {
if (T[i] == 0) continue;
m = min(m, Ds[i] / T[i]);
}
cout << m;
}
int main() {
task_328B();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
string n;
cin >> n;
string s;
cin >> s;
int a[10] = {0};
int b[10] = {0};
for (int i = 0; i < n.length(); i++) ++a[n[i] - '0'];
for (int i = 0; i < s.length(); i++) ++b[s[i] - '0'];
int an = 0;
b[6] += b[9];
b[2] += b[5];
b[9] = b[6];
b[5] = b[2];
while (1) {
int i;
for (i = 0; i < 10; i++) {
if (b[i] >= a[i]) {
if (i != 6 && i != 9 && i != 2 && i != 5)
b[i] -= a[i];
else {
b[i] -= a[i];
if (i == 9 || i == 5)
b[i - 3] -= a[i];
else
b[i + 3] -= a[i];
}
} else
break;
}
if (i == 10)
++an;
else
break;
}
cout << an << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int ft[10], f[10];
int n2 = 0, n6 = 0;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) ft[(int)s[i] - '0']++;
cin >> s;
for (int i = 0; i < s.length(); i++) f[(int)s[i] - '0']++;
bool noins = false;
int minf = 205;
for (int i = 0; i < 10; i++) {
if (i != 2 && i != 5 && i != 6 && i != 9) {
if (ft[i] > f[i]) {
noins = true;
break;
} else if (ft[i] != 0)
minf = min(f[i] / ft[i], minf);
}
}
if (ft[2] + ft[5] > f[2] + f[5]) noins = true;
if (ft[6] + ft[9] > f[6] + f[9]) noins = true;
if (noins)
printf("0");
else {
if (ft[2] + ft[5] > 0) minf = min(minf, (f[2] + f[5]) / (ft[2] + ft[5]));
if (ft[6] + ft[9] > 0) minf = min(minf, (f[6] + f[9]) / (ft[6] + ft[9]));
printf("%d", minf);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000 + 10;
const int Alpha = 27;
string str;
int sum[Alpha], need[Alpha];
int get(char a) {
if (a == '9') a = '6';
if (a == '5') a = '2';
return a - '0';
}
int main() {
int i;
cin >> str;
for ((i) = (0); (i) != ((int)str.size()); ++(i)) ++need[get(str[i])];
cin >> str;
for ((i) = (0); (i) != ((int)str.size()); ++(i)) ++sum[get(str[i])];
int ans = 1000000000;
for ((i) = (0); (i) != (Alpha); ++(i))
if (!sum[i] && need[i])
ans = 0;
else if (need[i])
ans = min(ans, sum[i] / need[i]);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool isTestcase = false;
void fun() {
string target, given;
cin >> target;
cin >> given;
unordered_map<char, long long int> counts;
for (long long int i = 0; i < given.size(); i++) {
if (given[i] == '5') {
counts['2']++;
} else if (given[i] == '9') {
counts['6']++;
} else {
counts[given[i]]++;
}
}
unordered_map<char, long long int> req;
for (long long int i = 0; i < target.size(); i++) {
if (target[i] == '5') target[i] = '2';
if (target[i] == '9') target[i] = '6';
req[target[i]]++;
}
long long int ans = INT_MAX;
for (auto i : req) {
ans = min(ans, counts[i.first] / i.second);
}
cout << ans << endl;
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
if (isTestcase) {
int t;
cin >> t;
for (int n = 0; n < t; n++) {
fun();
}
} else {
fun();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[20], b[20];
int main() {
string str;
cin >> str;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (int i = 0; str[i]; i++) {
a[str[i] - '0']++;
}
a[2] += a[5];
a[5] = a[2];
a[6] += a[9];
a[9] = a[6];
cin >> str;
for (int i = 0; str[i]; i++) {
b[str[i] - '0']++;
}
b[2] += b[5];
b[5] = b[2];
b[6] += b[9];
b[9] = b[6];
int ans = 1000000;
for (int i = 0; i < 10; i++)
if (a[i]) {
ans = min(ans, b[i] / a[i]);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> t >> s;
int freq[10], freq2[10];
for (int i = 0; i < 10; ++i) freq[i] = 0;
for (int i = 0; i < 10; ++i) freq2[i] = 0;
for (int i = 0; i < (int)s.size(); ++i) {
if (s[i] == '2' or s[i] == '5') {
freq[2]++;
freq[5]++;
} else if (s[i] == '6' or s[i] == '9') {
freq[6]++;
freq[9]++;
} else
freq[s[i] - '0']++;
}
for (int i = 0; i < (int)t.size(); ++i) {
freq2[t[i] - '0']++;
}
int ans = 10000000;
for (int i = 0; i < 10; ++i) {
if (freq2[i] != 0) {
if (i == 2 or i == 6)
ans = min(ans, freq[i] / (freq2[i] + freq2[i + 3]));
else if (i == 5 or i == 9)
ans = min(ans, freq[i] / (freq2[i] + freq2[i - 3]));
else
ans = min(ans, freq[i] / (freq2[i]));
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int convert(char ch) {
int res = ch - 48;
if (res == 9) res = 6;
if (res == 5) res = 2;
return res;
}
int main() {
int total[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int need[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int x;
cin >> x;
while (x > 0) {
int d = x % 10;
if (d == 9) d = 6;
if (d == 5) d = 2;
need[d]++;
x /= 10;
}
string s;
cin >> s;
for (int i = 0; i < s.size(); ++i) total[convert(s[i])]++;
int count = 0;
bool f = true;
while (f) {
for (int i = 0; i < 9; ++i)
if (total[i] >= need[i])
total[i] -= need[i];
else
f = false;
if (f) count++;
}
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t[10] = {0}, nums[10] = {0};
string s;
getline(cin, s);
stringstream ss(s);
char c;
while (ss.good()) {
ss >> c;
t[c - '0']++;
}
t[c - '0']--;
getline(cin, s);
stringstream ss1(s);
while (ss1.good()) {
ss1 >> c;
nums[c - '0']++;
}
nums[c - '0']--;
t[2] += t[5];
t[5] = 0;
t[6] += t[9];
t[9] = 0;
nums[2] += nums[5];
nums[5] = 0;
nums[6] += nums[9];
nums[9] = 0;
int min = 1000;
for (int i = 0; i < 10; i++)
if (t[i])
if (nums[i] / t[i] < min) min = nums[i] / t[i];
cout << min << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char Inpot[10];
char Example[220];
int Inpot_num[10], Example_num[10];
while (scanf("%s", Inpot) != EOF) {
memset(Inpot_num, 0, sizeof(Inpot_num));
memset(Example_num, 0, sizeof(Example_num));
scanf("%s", Example);
int In_len = strlen(Inpot), Exa_len = strlen(Example);
for (int i = 0; i < In_len; i++) Inpot_num[Inpot[i] - '0']++;
for (int i = 0; i < Exa_len; i++) Example_num[Example[i] - '0']++;
Inpot_num[2] += Inpot_num[5];
Inpot_num[6] += Inpot_num[9];
Inpot_num[5] = Inpot_num[9] = 0;
Example_num[2] += Example_num[5];
Example_num[6] += Example_num[9];
Example_num[5] = Example_num[9] = 0;
int ans = 99999;
for (int i = 0; i < 10; i++)
if (Inpot_num[i]) {
ans = min(ans, Example_num[i] / Inpot_num[i]);
}
if (ans == 99999) ans = 0;
printf("%d\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
int ans = 9999;
int pa[10] = {0}, pb[10] = {0};
cin >> a >> b;
for (int i = 0; i < a.length(); i++) {
if (a[i] == '5') {
a[i] = '2';
}
if (a[i] == '9') {
a[i] = '6';
}
pa[a[i] - '0']++;
}
for (int i = 0; i < b.length(); i++) {
if (b[i] == '5') {
b[i] = '2';
}
if (b[i] == '9') {
b[i] = '6';
}
pb[b[i] - '0']++;
}
for (int i = 0; i < 10; i++) {
if (pa[i] > 0 && pb[i] > 0) {
if (pb[i] / pa[i] < ans) {
ans = pb[i] / pa[i];
}
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int INFINITE = 0x3f3f3f3f;
template <class T>
inline void checkmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
return x * x;
}
template <class T>
inline T lowbit(T n) {
return (n ^ (n - 1)) & n;
}
template <class T>
inline int countbit(T n) {
return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));
}
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<string> VS;
#pragma comment(linker, "/STACK:200000000")
int main() {
int t;
cin >> t;
string s;
cin >> s;
int cntS[10] = {0};
for (int i = (int)(0); i < (int)(s.size()); i++) {
if (s[i] == '5') s[i] = '2';
if (s[i] == '9') s[i] = '6';
++cntS[s[i] - '0'];
}
int tt = t, cntT[10] = {0};
while (tt > 0) {
int c = tt % 10;
if (c == 6 || c == 9)
++cntT[6];
else if (c == 2 || c == 5)
++cntT[2];
else
++cntT[c];
tt /= 10;
}
int res = INFINITE;
for (int i = (int)(0); i < (int)(10); i++)
if (cntT[i]) {
checkmin(res, cntS[i] / cntT[i]);
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[10];
int main() {
bool b = 1;
int c = 0;
string s1, s2;
cin >> s1 >> s2;
for (int i = 0; i < s2.size(); i++) {
if (s2[i] == '0')
arr[0]++;
else if (s2[i] == '1')
arr[1]++;
else if (s2[i] == '2')
arr[2]++;
else if (s2[i] == '3')
arr[3]++;
else if (s2[i] == '4')
arr[4]++;
else if (s2[i] == '5')
arr[5]++;
else if (s2[i] == '6')
arr[6]++;
else if (s2[i] == '7')
arr[7]++;
else if (s2[i] == '8')
arr[8]++;
else if (s2[i] == '9')
arr[9]++;
}
while (b == 1) {
int i;
for (i = 0; i < s1.size(); i++) {
if (s1[i] == '0') {
if (arr[0] > 0)
arr[0]--;
else {
b = 0;
break;
}
} else if (s1[i] == '1') {
if (arr[1] > 0)
arr[1]--;
else {
b = 0;
break;
}
} else if (s1[i] == '2') {
if (arr[2] > 0)
arr[2]--;
else if (arr[5] > 0)
arr[5]--;
else {
b = 0;
break;
}
} else if (s1[i] == '3') {
if (arr[3] > 0)
arr[3]--;
else {
b = 0;
break;
}
} else if (s1[i] == '4') {
if (arr[4] > 0)
arr[4]--;
else {
b = 0;
break;
}
} else if (s1[i] == '5') {
if (arr[5] > 0)
arr[5]--;
else if (arr[2] > 0)
arr[2]--;
else {
b = 0;
break;
}
} else if (s1[i] == '6') {
if (arr[6] > 0)
arr[6]--;
else if (arr[9] > 0)
arr[9]--;
else {
b = 0;
break;
}
} else if (s1[i] == '7') {
if (arr[7] > 0)
arr[7]--;
else {
b = 0;
break;
}
} else if (s1[i] == '8') {
if (arr[8] > 0)
arr[8]--;
else {
b = 0;
break;
}
} else if (s1[i] == '9') {
if (arr[9] > 0)
arr[9]--;
else if (arr[6] > 0)
arr[6]--;
else {
b = 0;
break;
}
}
}
if (b == 0)
break;
else
c++;
}
cout << c << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
char s[1000], c[8];
int num[10];
bool is_ok() {
for (int i = 0; i < strlen(c); i++) {
if (num[c[i] - '0'] < 1) return 0;
num[c[i] - '0']--;
}
return 1;
}
int main() {
int t;
while (scanf("%d", &t) != EOF) {
memset(num, 0, sizeof(num));
scanf("%s", s);
sprintf(c, "%d", t);
for (int i = 0; i < strlen(c); i++)
if (c[i] == '9')
c[i] = '6';
else if (c[i] == '5')
c[i] = '2';
for (int i = 0; i < strlen(s); i++) {
if (s[i] == '9') s[i] = '6';
if (s[i] == '5') s[i] = '2';
num[s[i] - '0']++;
}
int ans = 0;
while (1) {
if (is_ok())
ans++;
else
break;
}
printf("%d\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string x;
string s;
cin >> x >> s;
vector<int> count(10, 0);
for (int i = 0; i < s.size(); i++) {
int a = (int)s[i] - 48;
count[a]++;
}
vector<int> count_in_x(10, 0);
for (int i = 0; i < x.size(); i++) {
int a = (int)x[i] - 48;
count_in_x[a]++;
}
vector<int> MIN(11, 1000);
for (int i = 0; i < 10; i++) {
if (count_in_x[i] > 0) {
if (i != 5 && (i != 2 && (i != 6 && i != 9))) {
MIN[i + 1] = min(MIN[i], count[i] / count_in_x[i]);
} else if (i == 2 || i == 5) {
MIN[i + 1] = min(
MIN[i], (count[2] + count[5]) / (count_in_x[2] + count_in_x[5]));
} else {
MIN[i + 1] = min(
MIN[i], (count[6] + count[9]) / (count_in_x[6] + count_in_x[9]));
}
} else {
MIN[i + 1] = MIN[i];
}
}
cout << MIN[10] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int a[10];
int b[10];
char str[205];
int main() {
int t;
cin >> t;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
while (t != 0) {
a[t % 10]++;
t /= 10;
}
a[2] += a[5];
a[5] = 0;
a[6] += a[9];
a[9] = 0;
cin >> str;
for (int i = 0; i < strlen(str); i++) {
b[str[i] - '0']++;
}
b[2] += b[5];
b[5] = 0;
b[6] += b[9];
b[9] = 0;
int ans = INF;
for (int i = 0; i < 10; i++) {
if (i == 5 || i == 9) continue;
if (a[i]) {
ans = min(ans, b[i] / a[i]);
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, j, ans = 0;
string s = " ";
vector<int> v1;
vector<int> v2;
cin >> t;
cin >> s;
for (i = 0; i < 10; i++) {
v1.push_back(0);
v2.push_back(0);
}
while (t) {
i = t % 10;
t = t / 10;
if (i == 2 || i == 5) {
v1[2]++;
} else if (i == 6 || i == 9) {
v1[6]++;
} else
v1[i]++;
}
j = 0;
while (j < s.size()) {
i = s[j] - '0';
if (i == 2 || i == 5) {
v2[2]++;
} else if (i == 6 || i == 9) {
v2[6]++;
} else
v2[i]++;
j++;
}
ans = 1000000;
for (i = 0; i < 10; i++) {
if (v1[i] != 0) {
ans = min<int>(ans, v2[i] / v1[i]);
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string zr, st;
long ttl[1000], need[1000], ans;
int main() {
ios_base::sync_with_stdio(0);
cin >> zr;
cin >> st;
for (int i = 0; i < st.size(); i++) {
ttl[st[i]]++;
}
ttl['2'] += ttl['5'];
ttl['6'] += ttl['9'];
ans = 0;
for (int i = 0; i < zr.size(); i++) {
if (zr[i] == '5')
need['2']++;
else if (zr[i] == '9')
need['6']++;
else
need[zr[i]]++;
}
ans = 1000000;
for (int i = '0'; i <= '9'; i++)
if (need[i] > 0) ans = min(ans, ttl[i] / need[i]);
cout << ans << endl;
cin.get();
cin.get();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string t, c;
cin >> t >> c;
int a[t.length()], x = 1;
for (int i = 0; i < t.length(); i++) {
a[i] = 0;
}
for (int i = 0; i < t.length(); i++) {
if (t[i] == '5') {
t[i] = '2';
}
if (t[i] == '9') {
t[i] = '6';
}
}
for (int i = 0; i < c.length(); i++) {
if (c[i] == '5') {
c[i] = '2';
}
if (c[i] == '9') {
c[i] = '6';
}
}
sort(t.begin(), t.end());
sort(c.begin(), c.end());
for (int i = 0; i < t.length(); i++) {
for (int j = 0; j < c.length(); j++) {
if (t[i] == c[j]) {
a[i]++;
}
}
}
for (int i = 1; i < t.length(); i++) {
if (t[i] == t[i - 1]) {
x++;
}
if (x > 2 && t[i - 2] != t[i - 1]) {
x--;
}
}
for (int i = 1; i < t.length(); i++) {
if (t[i] == t[i - 1]) {
a[i - 1] /= x;
}
}
int minn = a[0];
for (int i = 1; i < t.length(); i++) {
minn = min(minn, a[i]);
}
cout << minn;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, a[10], r[10], cnt = 0, temp = 0, len = 0, rem;
string dig;
for (i = 0; i < 10; i++) {
a[i] = 0;
r[i] = 0;
}
cin >> t;
cin >> dig;
len = dig.length();
for (i = 0; i < len; i++) a[dig[i] - 48]++;
len = 0;
temp = t;
while (temp > 0) {
r[temp % 10]++;
temp /= 10;
len++;
}
while (1) {
temp = 0;
for (i = 0; i < 10; i++) {
if (r[i]) {
if (a[i] >= r[i]) {
a[i] -= r[i];
temp += r[i];
} else if (a[i] > 0 && (i == 2 || i == 5 || i == 6 || i == 9)) {
rem = r[i] - a[i];
temp += a[i];
a[i] = 0;
if (i == 2 && a[5] >= rem) {
temp += rem;
a[5] -= rem;
} else if (i == 5 && a[2] >= rem) {
temp += rem;
a[2] -= rem;
} else if (i == 6 && a[9] >= rem) {
temp += rem;
a[9] -= rem;
} else if (i == 9 && a[6] >= rem) {
temp += rem;
a[6] -= rem;
}
} else if (i == 2 || i == 5 || i == 6 || i == 9) {
if (i == 2 && a[5] >= r[i]) {
temp += r[i];
a[5] -= r[i];
} else if (i == 5 && a[2] >= r[i]) {
temp += r[i];
a[2] -= r[i];
} else if (i == 6 && a[9] >= r[i]) {
temp += r[i];
a[9] -= r[i];
} else if (i == 9 && a[6] >= r[i]) {
temp += r[i];
a[6] -= r[i];
}
}
}
}
if (temp == len)
cnt++;
else
break;
}
cout << cnt;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s, t;
int cnt[256], op[256];
int main() {
cin >> s >> t;
for (int i = 0; i < t.size(); i++) {
cnt[t[i]]++;
}
for (int i = 0; i < 256; i++) op[i] = i;
swap(op['6'], op['9']);
swap(op['2'], op['5']);
int ans = 0;
while (true) {
for (int i = 0; i < s.size(); i++) {
if (cnt[s[i]])
cnt[s[i]]--;
else if (cnt[op[s[i]]])
cnt[op[s[i]]]--;
else {
printf("%d\n", ans);
return 0;
}
}
ans++;
}
return 0;
}
|
#include <bits/stdc++.h>
int dx[] = {0, -1, 0, 1, -1, 1, -1, 1};
int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int N = 2e6 + 5, oo = 1e9;
const long long mod = 1e9 + 7, MOD2 = 1e9 + 9, p1 = 1000003, p2 = 1000033;
const double pi = acos(-1);
using namespace std;
int freq[10];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string t, s;
cin >> t >> s;
int ans = 0;
multiset<int> st;
for (auto it : s) {
if (it == '9')
st.insert(6);
else if (it == '5')
st.insert(2);
else
st.insert(it - '0');
}
while (true) {
for (int i = 0; i < (int)(t).size(); i++) {
if (t[i] == '9') {
if (st.find(6) == st.end())
goto A;
else
st.erase(st.find(6));
} else if (t[i] == '5') {
if (st.find(2) == st.end())
goto A;
else
st.erase(st.find(2));
} else if (st.find(t[i] - '0') == st.end())
goto A;
else
st.erase(st.find(t[i] - '0'));
}
ans++;
}
A:
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string t, c;
int bits[10] = {0}, cn[10] = {0};
int count = 200;
cin >> t;
cin >> c;
for (int i = 0; i < c.length(); ++i) bits[c[i] - '0']++;
bits[2] += bits[5], bits[6] += bits[9];
for (int i = 0; i < t.length(); ++i) cn[t[i] - '0']++;
cn[2] += cn[5], cn[6] += cn[9], cn[5] = 0;
for (int i = 0; i <= 8; ++i) {
if (cn[i] != 0) {
if (bits[i] == 0) break;
count = min(count, bits[i] / cn[i]);
}
}
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
string str;
cin >> t >> str;
int l = str.size();
int v1[10] = {0}, v2[10] = {0};
while (t) {
v1[t % 10]++;
t /= 10;
}
for (int i = 0; i < l; i++) {
v2[str[i] - '0']++;
}
v1[2] += v1[5];
v1[5] = 0;
v1[6] += v1[9];
v1[9] = 0;
v2[2] += v2[5];
v2[5] = 0;
v2[6] += v2[9];
v2[9] = 0;
int ans = 1e9;
for (int i = 0; i < 8; i++) {
if (v1[i] == 0) continue;
ans = min(ans, v2[i] / v1[i]);
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s1, s2;
cin >> s1 >> s2;
int p[10] = {0};
int q[10] = {0};
int len1 = s1.size();
int len2 = s2.size();
for (int i = 0; i < len1; i++) {
if (s1[i] == '9')
p[(int)s1[i] - 51]++;
else if (s1[i] == '5')
p[(int)s1[i] - 51]++;
else
p[(int)s1[i] - 48]++;
}
for (int i = 0; i < len2; i++) {
if (s2[i] == '9')
q[(int)s2[i] - 51]++;
else if (s2[i] == '5')
q[(int)s2[i] - 51]++;
else
q[(int)s2[i] - 48]++;
}
int flag = 0;
int r[10] = {0};
int count = 0;
for (int i = 0; i < 10; i++) {
if (p[i] > q[i]) {
flag++;
break;
} else if (p[i] > 0 && q[i] > 0) {
r[count++] = q[i] / p[i];
}
}
if (flag > 0)
cout << "0";
else {
sort(r, r + count);
cout << r[0];
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string t;
cin >> t;
string s;
cin >> s;
long long int c = INT_MAX;
map<char, long long int> m, n;
if (s.size() < t.size()) {
cout << "0" << endl;
} else {
for (int i = 0; i < t.size(); i++) {
if (t[i] == '2' || t[i] == '5') {
m['2']++;
} else if (t[i] == '6' || t[i] == '9') {
m['6']++;
} else {
m[t[i]]++;
}
}
for (int i = 0; i < s.size(); i++) {
if (s[i] == '2' || s[i] == '5') {
n['2']++;
} else if (s[i] == '6' || s[i] == '9') {
n['6']++;
} else {
n[s[i]]++;
}
}
for (auto &x : n) {
for (auto &l : m) {
if (x.first == l.first) {
if (x.second - l.second >= 0) {
c = min(c, x.second / l.second);
}
}
}
}
cout << c << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[11], b[11], ans = 1000000;
string s;
int main() {
cin >> s;
for (int i = 0; i < s.length(); i++) a[s[i] - 48]++;
cin >> s;
for (int i = 0; i < s.length(); i++) b[s[i] - 48]++;
a[2] += a[5], b[2] += b[5], a[6] += a[9], b[6] += b[9];
for (int i = 0; i <= 9; i++)
if (a[i] > 0 && i != 5 && i != 9) ans = min(ans, b[i] / a[i]);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string t;
string ice;
cin >> t >> ice;
int trr[10];
memset(trr, 0, sizeof trr);
int icerr[10];
memset(icerr, 0, sizeof icerr);
int ln = ice.size();
for (int idx = 0; idx < ln; idx++) {
int tmp = ice[idx] - '0';
++icerr[tmp];
}
icerr[2] += icerr[5];
icerr[6] += icerr[9];
icerr[5] = 0;
icerr[9] = 0;
ln = t.size();
for (int idx = 0; idx < ln; idx++) {
++trr[t[idx] - '0'];
}
trr[2] += trr[5];
trr[6] += trr[9];
trr[5] = 0;
trr[9] = 0;
bool flag = false;
int count = 0;
set<int> st;
for (int idx = 0; idx < ln; idx++) {
if ((t[idx] - '0') == 5)
st.insert(2);
else if ((t[idx] - '0') == 9)
st.insert(6);
else
st.insert(t[idx] - '0');
}
set<int>::iterator idx;
while (true) {
for (idx = st.begin(); idx != st.end(); idx++) {
if (icerr[*idx] < trr[*idx]) {
flag = true;
break;
} else {
icerr[*idx] -= trr[*idx];
}
}
if (flag) break;
++count;
}
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string t;
std::cin >> t;
std::map<char, size_t> tc;
for (char c : t) {
if (c == '5') {
c = '2';
}
if (c == '9') {
c = '6';
}
tc[c] += 1;
}
std::string s;
std::cin >> s;
std::map<char, size_t> sc;
for (char c : s) {
if (c == '5') {
c = '2';
}
if (c == '9') {
c = '6';
}
sc[c] += 1;
}
size_t result = 0;
for (;;) {
bool ok = true;
for (const auto& [k, v] : tc) {
if (sc[k] >= v) {
sc[k] -= v;
} else {
ok = false;
break;
}
}
if (!ok) {
break;
}
result += 1;
}
std::cout << result << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
long long raised(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) {
res = res * x;
}
y = y >> 1;
x = x * x;
}
return res;
}
long long raisedmod(long long x, long long y, long long p) {
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) {
res = (res * x) % p;
}
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long fact(long long n) {
long long res = 1;
for (long long i = 2; i <= n; i++) res = res * i;
return res;
}
long long nCr(long long n, long long r) {
return fact(n) / (fact(r) * fact(n - r));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long t;
t = 1;
while (t--) {
string t, s;
cin >> t >> s;
map<char, long long> mp;
mp['0'] = 0;
mp['1'] = 0;
mp['2'] = 0;
mp['3'] = 0;
mp['4'] = 0;
mp['5'] = 0;
mp['6'] = 0;
mp['7'] = 0;
mp['8'] = 0;
mp['9'] = 0;
for (long long i = 0; i < s.size(); i++) {
mp[s[i]]++;
}
mp['6'] += mp['9'];
mp['9'] = mp['6'];
mp['5'] += mp['2'];
mp['2'] = mp['5'];
map<char, long long> mp1;
vector<long long> v;
for (long long i = 0; i < t.size(); i++) {
mp1[t[i]]++;
}
mp1['6'] += mp1['9'];
mp1['9'] = mp1['6'];
mp1['5'] += mp1['2'];
mp1['2'] = mp1['5'];
for (auto &it : mp1) {
if (it.second != 0) v.push_back(mp[it.first] / it.second);
}
cout << *min_element(v.begin(), v.end()) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char s[201];
int a[10], b[10];
int main() {
int n, i, ret = INT_MAX;
scanf("%s", s);
n = strlen(s);
for (i = 0; i < n; i++) a[s[i] - '0']++;
a[2] += a[5];
a[6] += a[9];
a[5] = a[9] = 0;
scanf("%s", s);
n = strlen(s);
for (i = 0; i < n; i++) b[s[i] - '0']++;
b[2] += b[5];
b[6] += b[9];
b[5] = b[9] = 0;
for (i = 0; i < 10; i++)
if (a[i]) ret = min(ret, b[i] / a[i]);
printf("%d", ret);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double eps(1e-8);
int cnt[100];
char s[500];
int has[100];
int main() {
scanf("%s", s);
int n = strlen(s);
for (int i = 0; i < n; i++) {
if (s[i] == '2' || s[i] == '5') {
cnt[2]++;
continue;
}
if (s[i] == '6' || s[i] == '9') {
cnt[6]++;
continue;
}
cnt[s[i] - '0']++;
}
scanf("%s", s);
n = strlen(s);
for (int i = 0; i < n; i++) {
if (s[i] == '2' || s[i] == '5') {
has[2]++;
continue;
}
if (s[i] == '6' || s[i] == '9') {
has[6]++;
continue;
}
has[s[i] - '0']++;
}
int ans = 99999;
for (int i = 0; i < 10; i++) {
if (i == '5' || i == '9') continue;
if (cnt[i]) ans = min(ans, has[i] / cnt[i]);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int t[10] = {0}, l[10] = {0};
int min = 300;
char ch;
while ((ch = getchar()) != '\n') t[ch - 48]++;
while ((ch = getchar()) != '\n') l[ch - 48]++;
t[6] += t[9];
t[9] = t[6];
t[2] += t[5];
t[5] = t[2];
l[6] += l[9];
l[9] = l[6];
l[2] += l[5];
l[5] = l[2];
for (ch = 0; ch < 10; ch++) {
int r;
if (t[ch]) {
r = l[ch] / t[ch];
if (r < min) min = r;
}
}
if (min < 300)
printf("%d\n", min);
else
printf("0\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int piece_cot[10];
int t_cot[10];
int main() {
int i, l1, l2;
string t, pieces;
while (cin >> t >> pieces) {
int min = -1;
l1 = t.length();
l2 = pieces.length();
for (i = 0; i < l1; i++) {
if (t[i] == '2' || t[i] == '5')
t_cot[2]++;
else if (t[i] == '6' || t[i] == '9')
t_cot[6]++;
else
t_cot[t[i] - '0']++;
}
for (i = 0; i < l2; i++) {
if (pieces[i] == '2' || pieces[i] == '5')
piece_cot[2]++;
else if (pieces[i] == '6' || pieces[i] == '9')
piece_cot[6]++;
else
piece_cot[pieces[i] - '0']++;
}
for (i = 0; i < 10; i++) {
if (i != 5 && i != 9) {
if (t_cot[i] > 0) {
int m = (piece_cot[i] / t_cot[i]);
if (min == -1 || m < min) min = m;
}
}
}
cout << min << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n = 1, m, k, l = 0, x, y, z;
int a[10], b[10];
string s, s1;
int main() {
cin >> s1 >> s;
for (int i = 0; i < s1.length(); ++i) a[s1[i] - '0']++;
for (int i = 0; i < s.length(); ++i) b[s[i] - '0']++;
a[2] += a[5];
a[6] += a[9];
b[2] += b[5];
b[6] += b[9];
n = 100000000;
for (int i = 0; i < 10; ++i) {
if (i == 5 || i == 9) continue;
if (a[i] > b[i])
n = 0;
else if (a[i] == 0)
continue;
else
n = min(n, b[i] / a[i]);
}
cout << n;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char a[202];
bool flag[202];
int main() {
int t, i, j;
char ss[10];
scanf("%d", &t);
scanf("%s", a);
int count = 0;
while (t > 9) {
ss[count++] = (t % 10 + '0');
t /= 10;
}
ss[count++] = (t + '0');
int re[11], temp = 0, two = 0, six = 0, cou[20];
memset(re, 0, sizeof(re));
memset(cou, 0, sizeof(cou));
memset(flag, 0, sizeof(flag));
int len = strlen(a);
for (j = 0; j < len; j++) {
if (!flag[j]) {
re[a[j] - '0']++;
flag[j] = 1;
}
}
for (i = 0; i < count; i++) {
cou[ss[i] - '0']++;
}
int min = INT_MAX - 1;
count = (re[2] + re[5]);
re[2] = re[5] = count;
count = re[6] + re[9];
re[6] = re[9] = count;
cou[6] += cou[9];
cou[9] = cou[6];
cou[2] += cou[5];
cou[5] = cou[2];
for (i = 0; i < 10; i++) {
if (!cou[i]) continue;
if ((re[i] / cou[i]) < min) min = re[i] / cou[i];
}
printf("%d\n", min);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, count = 0, seq_array[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
num_array[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, max = 0;
long long int num;
string seq;
cin >> num >> seq;
do {
if (num % 10 == 5) {
num_array[2] += 1;
} else if (num % 10 == 9) {
num_array[6] += 1;
} else
num_array[num % 10] += 1;
num = num / 10;
count++;
} while (num != 0);
i = 0;
do {
if ((int(seq[i]) - 48) == 5) {
seq_array[2] += 1;
} else if ((int(seq[i]) - 48) == 9) {
seq_array[6] += 1;
} else
seq_array[int(seq[i]) - 48] += 1;
i++;
} while (i <= seq.length());
do {
count = 0;
for (i = 0; i < 10; i++) {
if (num_array[i] != 0) {
seq_array[i] = seq_array[i] - num_array[i];
if (seq_array[i] < 0) {
count = 1;
break;
}
}
}
max++;
} while (count != 1);
cout << --max;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[10] = {0};
int arr_num[10] = {0};
int t;
string line;
cin >> t;
getline(cin, line);
getline(cin, line);
for (int i = 0; i < line.size(); i++) {
if (line[i] == '2' || line[i] == '5')
arr[2]++;
else if (line[i] == '6' || line[i] == '9')
arr[6]++;
else
arr[(int)line[i] - '0']++;
}
int tmp;
vector<int> num;
while (t) {
tmp = t % 10;
if (tmp == 6 || tmp == 9)
arr_num[6]++;
else if (tmp == 2 || tmp == 5)
arr_num[2]++;
else
arr_num[tmp]++;
t /= 10;
}
int res = 0;
bool flag = 0, can;
while (!flag) {
can = 1;
for (int i = 0; i < 10; i++) {
if (arr_num[i] == 0)
continue;
else if (arr_num[i]) {
if (arr[i] < arr_num[i]) {
can = 0;
flag = 1;
break;
}
if (arr[i] >= arr_num[i]) arr[i] -= arr_num[i];
if (arr[i] < arr_num[i]) {
flag = 1;
}
}
}
if (can) res++;
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int d[20];
vector<int> value;
int main(int argc, const char* argv[]) {
int t;
cin >> t;
cin >> s;
for (int i = 0; i < s.size(); i++) {
int tmp = s[i] - '0';
bool flag = false;
if ((tmp == 5) || (tmp == 2)) {
d[5]++;
d[2]++;
flag = true;
}
if ((tmp == 6) || (tmp == 9)) {
d[6]++;
d[2]++;
flag = true;
}
if (flag == false) d[tmp]++;
}
while (t > 0) {
value.push_back(t % 10);
t /= 10;
}
long long answer = 0;
while (true) {
for (int i = 0; i < value.size(); i++) {
bool flag = false;
int tmp = value[i];
if ((tmp == 5) || (tmp == 2)) {
d[5]--;
d[2]--;
flag = true;
}
if ((tmp == 6) || (tmp == 9)) {
d[6]--;
d[2]--;
flag = true;
}
if (flag == false) d[tmp]--;
}
for (int i = 0; i < 10; i++)
if (d[i] < 0) {
cout << answer << endl;
return 0;
}
answer++;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long Calculation(int y, int m, int d) {
if (m < 3) {
y -= 1;
m += 12;
}
return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
bool cmp(int a, int b) { return a > b; }
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
inline string r(string n) {
string k = "";
for (int i = n.size() - 1; i >= 0; i--) k += n[i];
return k;
}
int main() {
int ans[10] = {0}, a1[10] = {0};
string s1, s2;
int i, j, n, t;
cin >> s1 >> s2;
for (i = 0; i < s1.length(); i++) {
int x = s1[i] - '0';
ans[x]++;
}
for (i = 0; i < s2.length(); i++) {
int y = s2[i] - '0';
a1[y]++;
}
int ansx = 0x3f3f3f3f, f1 = 0, f2 = 0;
for (i = 0; i <= 9; i++) {
if (ans[i] == 0) {
continue;
} else {
if (i == 6 || i == 9 || i == 2 || i == 5) {
if (i == 6 || i == 9 && f1 == 0) {
f1 = 1;
int d2;
d2 = (a1[6] + a1[9]) / (ans[6] + ans[9]);
ansx = min(ansx, d2);
} else if (i == 2 || i == 5 && f2 == 0) {
f2 = 1;
int d3;
d3 = (a1[2] + a1[5]) / (ans[2] + ans[5]);
ansx = min(ansx, d3);
}
continue;
}
if (ans[i] > a1[i]) {
cout << 0 << endl;
return 0;
} else {
int d1 = a1[i] / ans[i];
ansx = min(ansx, d1);
}
}
}
cout << ansx << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[10], n[10];
int main() {
int t;
cin >> t;
while (t) {
int m = t % 10;
if (m == 9) a[6]++;
if (m == 5) a[2]++;
if (m != 5 and m != 9) a[m]++;
t /= 10;
}
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '9') n[6]++;
if (s[i] == '5') n[2]++;
if (s[i] != 5 and s[i] != 9) n[s[i] - '0']++;
}
int ans = 100000;
for (int i = 0; i <= 10; i++)
if (a[i] != 0) ans = min(int(n[i] / a[i]), ans);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
string s;
cin >> s;
string t;
cin >> t;
unordered_map<char, long long int> umap, umap2;
for (auto ele : s) {
if (ele == '9')
umap['6']++;
else if (ele == '5')
umap['2']++;
else
umap[ele]++;
}
for (auto ele : t) {
if (ele == '9')
umap2['6']++;
else if (ele == '5')
umap2['2']++;
else
umap2[ele]++;
}
long long int ans = LONG_MAX;
for (auto ele : umap) ans = min(ans, umap2[ele.first] / ele.second);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int v[27], need[27];
int main() {
string s, t;
int i, j;
cin >> t;
cin >> s;
for (i = 0; i < s.size(); i++) {
if (s[i] == '2' || s[i] == '5')
v[2]++, v[5]++;
else if (s[i] == '6' || s[i] == '9')
v[6]++, v[9]++;
else {
v[s[i] - '0']++;
}
}
int ans = 999999999;
for (i = 0; i < t.size(); i++) {
if (t[i] == '6') t[i] = '9';
if (t[i] == '5') t[i] = '2';
need[t[i] - '0']++;
}
for (i = 0; i <= 26; i++) {
if (need[i] > 0) {
ans = min(ans, v[i] / need[i]);
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string T, S;
while (cin >> T >> S) {
int Ti[10], Pic[10], i, j, k, Min = -1, Max;
memset(Ti, 0, sizeof(Ti));
memset(Pic, false, sizeof(Pic));
for (i = 0; i < S.size(); i++) {
S[i] -= 48;
if (S[i] == 5)
Pic[2]++;
else if (S[i] == 9)
Pic[6]++;
else
Pic[int(S[i])]++;
}
for (i = 0; i < T.size(); i++) {
T[i] -= 48;
if (T[i] == 5)
Ti[2]++;
else if (T[i] == 9)
Ti[6]++;
else
Ti[int(T[i])]++;
}
for (i = 0; i < 10; i++) {
if (Ti[i] != 0 && Pic[i] != 0 && (Min > Pic[i] / Ti[i] || Min == -1))
Min = Pic[i] / Ti[i];
}
cout << Min << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
int i, j, res = 200, s1[10] = {0}, s2[10] = {0};
cin >> a;
for (i = 0; i < a.length(); i++) s1[a[i] - '0']++;
cin >> b;
for (i = 0; i < b.length(); i++) s2[b[i] - '0']++;
s1[6] += s1[9];
s1[2] += s1[5];
s2[6] += s2[9];
s2[2] += s2[5];
for (i = 0; i <= 9; i++) {
if (i == 9 || i == 5) continue;
if (s1[i] > 0) res = min(res, s2[i] / s1[i]);
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
int a, b, c;
string s;
vector<int> v;
vector<int> req;
vector<int> ans;
int freq_1[201] = {0};
int freq_2[2001] = {0};
cin >> a;
cin >> s;
while (a > 0) {
req.push_back(a % 10);
a /= 10;
}
for (int i = 0; i < s.size(); i++) {
v.push_back((s[i] - 48));
}
for (int i = 0; i < v.size(); i++) {
freq_1[v[i]]++;
}
for (int i = 0; i < req.size(); i++) {
freq_2[req[i]]++;
}
freq_2[2] += freq_2[5];
freq_2[5] = freq_2[2];
freq_2[6] += freq_2[9];
freq_2[9] = freq_2[6];
b = freq_2[2];
c = freq_2[6];
freq_1[2] += freq_1[5];
freq_1[5] = freq_1[2];
freq_1[6] += freq_1[9];
freq_1[9] = freq_1[6];
for (int i = 0; i < req.size(); i++) {
if (req[i] == 2 || req[i] == 5) {
if (b > 0) {
ans.push_back(freq_1[req[i]] / b);
}
} else if (req[i] == 6 || req[i] == 9) {
if (c > 0) {
ans.push_back(freq_1[req[i]] / c);
}
} else
ans.push_back(freq_1[req[i]] / freq_2[req[i]]);
}
sort(ans.begin(), ans.end());
cout << ans[0];
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
int main() {
int a, b, x, y, s = 0, c = 0, k, n, m, p, q;
vector<int> z;
char ch;
cin >> n;
string e;
cin >> e;
int h[11] = {0};
for (int i = 0; i < int(e.size()); i++) {
if (e[i] == '2' || e[i] == '5') {
h[2]++;
} else {
if (e[i] == '6' || e[i] == '9') {
h[6]++;
} else {
h[e[i] - '0']++;
}
}
}
int hh[11] = {0};
while (n != 0) {
a = n % 10;
if (a == 2 || a == 5) {
hh[2]++;
} else {
if (a == 6 || a == 9) {
hh[6]++;
} else {
hh[a]++;
}
}
n /= 10;
}
int mi = 1000000;
for (int i = 0; i < int(9); i++) {
if (i == 5) continue;
if (hh[i] != 0) {
a = h[i] / hh[i];
if (a < mi) mi = a;
}
}
cout << mi << endl;
;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, N = 1e6 + 1;
int main() {
long long t;
string s;
cin >> t >> s;
map<long long, long long> mp;
for (long long i = 0; i < s.length(); i++) {
long long p = s[i] - '0';
if (p == 2 || p == 5) {
mp[2]++;
mp[5]++;
} else if (p == 6 || p == 9) {
mp[6]++;
mp[9]++;
} else
mp[p]++;
}
long long m = t, ans = 0;
while (1) {
if (m == 0) {
ans++;
m = t;
}
long long g = m % 10;
m = m / 10;
if (mp[g] == 0)
break;
else if (g == 2 || g == 5) {
mp[2]--;
mp[5]--;
} else if (g == 6 || g == 9) {
mp[6]--;
mp[9]--;
} else
mp[g]--;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char t[7], s[202];
int a[10], b[10];
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
cin >> t >> s;
int len1, len2;
len1 = strlen(t);
len2 = strlen(s);
for (int i = 0; i < len2; i++) a[s[i] - '0']++;
for (int i = 0; i < len1; i++) b[t[i] - '0']++;
b[2] += b[5];
b[5] = 0;
b[6] += b[9];
b[9] = 0;
a[2] += a[5];
a[5] = 0;
a[6] += a[9];
a[9] = 0;
int minm = 1e6;
for (int i = 0; i < 10; i++)
if (b[i] != 0) {
int c = a[i] / b[i];
if (c < minm) minm = c;
}
cout << minm << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793;
int a[10];
int b[10];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s, t;
cin >> s >> t;
for (int i = 0; i < t.size(); i++) {
if (t[i] == '2' or t[i] == '5') {
a[5]++;
a[2]++;
} else if (t[i] == '6' or t[i] == '9') {
a[6]++;
a[9]++;
} else {
a[t[i] - '0']++;
}
}
for (int i = 0; i < s.size(); i++) {
if (s[i] == '2' or s[i] == '5') {
b[5]++;
b[2]++;
} else if (s[i] == '6' or s[i] == '9') {
b[6]++;
b[9]++;
} else {
b[s[i] - '0']++;
}
}
int ans = 0;
int x = 0;
for (int i = 0; i < 10; i++) {
if (b[i] and x)
ans = min(a[i] / b[i], ans);
else if (b[i]) {
ans = a[i] / b[i];
x = 1;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long modPow(int X, int Y) {
long long Temp, Ans;
long long M = (long long)pow(10, k);
if (!Y) return 1;
Temp = modPow(X, Y / 2);
Ans = (Temp * Temp) % M;
if (!(Y & 1))
return Ans;
else
return (X * Ans) % M;
}
char a[201];
int arr[10], b[10];
int main() {
int t, i, j = 0, te;
scanf("%d", &t);
memset(arr, 0, sizeof(arr));
memset(b, 0, sizeof(arr));
scanf("%s", &a);
n = strlen(a);
for (i = 0; i < n; i++) {
if (a[i] == '5')
arr[2]++;
else if (a[i] == '9')
arr[6]++;
else
arr[a[i] - '0']++;
}
for (; t != 0; t = t / 10) {
j = t % 10;
if (j == 5)
b[2]++;
else if (j == 9)
b[6]++;
else
b[j]++;
}
int ma = 200;
for (i = 0; i < 10; i++) {
if (b[i]) {
ma = min(ma, arr[i] / b[i]);
}
}
cout << ma;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, a = 0, b = 1, c = 0, d, t, n, e = 0;
string s;
vector<int> v;
vector<int> u;
cin >> t;
cin >> s;
for (i = 5; i >= 0; i--) {
b = pow(10, i) + .5;
a = t / b;
if (a > 0) e = 1;
if (e == 1) {
if (a == 5) a = 2;
if (a == 9) a = 6;
v.push_back(a);
t = t % b;
}
}
int l = v.size();
u = v;
for (i = 0; i <= v.size() - 1; i++) {
for (j = i + 1; j <= v.size() - 1; j++) {
if (v[i] == v[j]) {
v.erase(v.begin() + j);
j--;
}
}
}
n = v.size();
int r[n];
int p[n];
int m[n];
for (i = 0; i <= n - 1; i++) {
for (j = 0; j <= l - 1; j++) {
if (v[i] == u[j]) {
c++;
}
}
r[i] = c;
c = 0;
}
for (i = 0; i <= s.length() - 1; i++) {
if (s[i] == '9') {
s[i] = '6';
}
if (s[i] == '5') {
s[i] = '2';
}
}
for (i = 0; i <= n - 1; i++) {
for (j = 0; j <= s.length() - 1; j++) {
if ('0' + v[i] == s[j]) {
c++;
}
}
p[i] = c;
c = 0;
}
for (i = 0; i <= n - 1; i++) {
a = p[i] / r[i];
m[i] = a;
}
b = m[0];
for (i = 0; i <= n - 1; i++) {
if (m[i] < b) b = m[i];
}
cout << b;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[10] = {0}, t[10] = {0};
char c;
int re = 200, i = 0;
while (cin.get(c), c != '\n') t[c - '0']++;
while (cin.get(c), c != '\n') a[c - '0']++;
t[2] += t[5];
a[2] += a[5];
t[5] = a[5] = 0;
t[6] += t[9];
a[6] += a[9];
t[9] = a[9] = 0;
for (i = 0; i < 9; ++i) {
if (t[i]) {
re = a[i] / t[i] < re ? a[i] / t[i] : re;
}
}
cout << re << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string t;
int need[10];
int have[10];
for (int i = 0; i <= 9; i++) need[i] = 0, have[i] = 0;
cin >> t;
for (int i = 0; i < t.size(); i++) {
if (t[i] == '9') t[i] = '6';
if (t[i] == '5') t[i] = '2';
need[t[i] - '0']++;
}
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '9') s[i] = '6';
if (s[i] == '5') s[i] = '2';
have[s[i] - '0']++;
}
int ans = 999999;
for (int i = 0; i <= 9; i++) {
if (need[i] == 0) continue;
int numbers = have[i] / need[i];
ans = min(ans, numbers);
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 7;
const int M = 1e9;
const int inf = 1e9 + 7;
const int base = 1e9 + 9;
const double pi = acos(-1);
const double ep = 1e-9;
int sl[10];
int x[10];
int n;
string s;
int main() {
cin >> n >> s;
for (int i = (int)0; i < (int)s.size(); i++) {
int u = s[i] - '0';
if (u == 5)
x[2]++;
else if (u == 9)
x[6]++;
else
x[u]++;
}
if (n == 0)
cout << x[0] << endl;
else {
while (n > 0) {
int u = n % 10;
if (u == 5)
sl[2]++;
else if (u == 9)
sl[6]++;
else
sl[u]++;
n /= 10;
}
int res = inf;
for (int i = (int)0; i < (int)10; i++)
if (sl[i] > 0) res = min(res, x[i] / sl[i]);
cout << res;
}
}
|
#include <bits/stdc++.h>
using namespace std;
struct abc {
int x;
int win;
} s;
int main() {
int n, k, i, coun = 0, j, x[11] = {0}, y[11] = {0};
string t;
cin >> t;
for (i = 0; i < t.length(); i++) {
if (t[i] == '5') t.replace(i, 1, "2");
if (t[i] == '9') t.replace(i, 1, "6");
x[t[i] - '0']++;
}
string a;
cin >> a;
for (j = a.length() - 1; j >= 0; j--) {
if (a[j] == '5') a.replace(j, 1, "2");
if (a[j] == '9') a.replace(j, 1, "6");
y[a[j] - '0']++;
}
int min = 10000000;
for (i = 0; i < 10; i++) {
if (x[i] && y[i] / x[i] < min) min = y[i] / x[i];
}
cout << min << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
template <typename X>
inline bool minimize(X& p, X q) {
if (p <= q) return 0;
p = q;
return 1;
}
template <typename X>
inline bool maximize(X& p, X q) {
if (p >= q) return 0;
p = q;
return 1;
}
int T;
char S[205];
int cnt1[10], cnt2[10];
int main() {
cin >> T >> S;
for (int i = T; i; i /= 10) ++cnt1[i % 10];
cnt1[2] += cnt1[5];
cnt1[6] += cnt1[9];
cnt1[5] = cnt1[9] = 0;
for (int i = 0; S[i]; ++i) ++cnt2[S[i] - '0'];
cnt2[2] += cnt2[5];
cnt2[6] += cnt2[9];
cnt2[5] = cnt2[9] = 0;
int ans = INF;
for (int i = 0; i < 10; ++i)
if (cnt1[i]) minimize(ans, cnt2[i] / cnt1[i]);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
int mi;
int c[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int d[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int j[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int max = 0;
cin >> a;
cin >> b;
for (int i = 0; i < b.size() || i < a.size(); i++) {
if (b[i] == '6') b[i] = '9';
if (b[i] == '2') b[i] = '5';
if (a[i] == '6') a[i] = '9';
if (a[i] == '2') a[i] = '5';
if (i <= a.size()) {
if (a[i] == '0') ++c[0];
if (a[i] == '1') ++c[1];
if (a[i] == '3') ++c[3];
if (a[i] == '4') ++c[4];
if (a[i] == '5') ++c[5];
if (a[i] == '7') ++c[7];
if (a[i] == '8') ++c[8];
if (a[i] == '9') ++c[9];
}
if (b[i] == '0') ++d[0];
if (b[i] == '1') ++d[1];
if (b[i] == '3') ++d[3];
if (b[i] == '4') ++d[4];
if (b[i] == '5') ++d[5];
if (b[i] == '7') ++d[7];
if (b[i] == '8') ++d[8];
if (b[i] == '9') ++d[9];
}
if (d[0] != 0 && c[0] != 0) j[0] = d[0] / c[0];
if (d[1] != 0 && c[1] != 0) j[1] = d[1] / c[1];
if (d[3] != 0 && c[3] != 0) j[3] = d[3] / c[3];
if (d[4] != 0 && c[4] != 0) j[4] = d[4] / c[4];
if (d[5] != 0 && c[5] != 0) j[5] = d[5] / c[5];
if (d[7] != 0 && c[7] != 0) j[7] = d[7] / c[7];
if (d[8] != 0 && c[8] != 0) j[8] = d[8] / c[8];
if (d[9] != 0 && c[9] != 0) j[9] = d[9] / c[9];
if (j[0] < j[1] && j[0] != 0) {
if (c[0] != 0) max = j[0];
} else if (c[1] != 0) {
max = j[1];
}
if (max > j[3] || max == 0)
if (c[3] != 0) max = j[3];
if (max > j[4] || max == 0)
if (c[4] != 0) {
max = j[4];
}
if (max > j[5] || max == 0)
if (c[5] != 0) max = j[5];
if (max > j[7] || max == 0)
if (c[7] != 0) max = j[7];
if (max > j[8] || max == 0)
if (c[8] != 0) max = j[8];
if (max > j[9] || max == 0)
if (c[9] != 0) max = j[9];
cout << max;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[10], b[10];
int wyn = 10007;
void test() {
string t, x;
cin >> t >> x;
for (int i = 0; t[i]; i++) a[t[i] - '0']++;
for (int i = 0; x[i]; i++) b[x[i] - '0']++;
a[5] += a[2];
a[2] = 0;
a[6] += a[9];
a[9] = 0;
b[5] += b[2];
b[2] = 0;
b[6] += b[9];
b[9] = 0;
for (int i = 0; i <= 9; i++)
if (a[i]) wyn = min(wyn, b[i] / a[i]);
printf("%d\n", wyn);
}
int main() {
int t = 1;
while (t--) test();
return 0;
}
|
#include <bits/stdc++.h>
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
using namespace std;
void solve() {
long long n;
cin >> n;
string s;
cin >> s;
long long nc[10], second[10], n2 = 0, n6 = 0, s2 = 0, s6 = 0;
memset(nc, 0, sizeof(nc)), memset(second, 0, sizeof(second));
while (n != 0) {
long long t = n % 10;
if (t == 5 || t == 2)
n2++;
else if (t == 6 || t == 9)
n6++;
else
nc[t]++;
n /= 10;
}
for (auto it : s) {
long long t = it - '0';
if (t == 5 || t == 2)
s2++;
else if (t == 6 || t == 9)
s6++;
else
second[t]++;
}
long long mn = INF;
for (long long i = 0; i < 10; i++) {
if (i != 2 && i != 5 && i != 6 && i != 9 && nc[i] != 0) {
long long t = second[i] / nc[i];
mn = min(t, mn);
}
}
long long a2 = INF, a6 = INF;
if (n2 > 0) a2 = s2 / n2;
if (n6 > 0) a6 = s6 / n6;
mn = min(mn, a2);
mn = min(mn, a6);
cout << mn;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string z;
cin >> z;
string s;
cin >> s;
map<char, int> m;
for (auto i : z) m[i]++;
map<char, int> m1;
for (auto i : s) m1[i]++;
int ans = INT_MAX;
int a = INT_MAX;
if (m['2'] != 0 || m['5'] != 0) a = (m1['2'] + m1['5']) / (m['2'] + m['5']);
ans = min(ans, a);
int b = INT_MAX;
if (m['6'] != 0 || m['9'] != 0) b = (m1['6'] + m1['9']) / (m['6'] + m['9']);
ans = min(ans, b);
for (auto i : m)
if (i.first != '2' && i.first != '5' && i.first != '6' && i.first != '9')
if (i.second != 0) ans = min(ans, m1[i.first] / i.second);
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
string a;
int long long na[9], nb[9];
int long long c = 10000000;
int main() {
cin >> a;
for (int x = 0; x < 9; x++) {
na[x] = 0;
nb[x] = 0;
}
for (int x = 0; x < a.length(); x++) {
if (a[x] == '9') {
na[6]++;
} else if (a[x] == '5') {
na[2]++;
} else {
na[a[x] - '0']++;
}
}
cin >> a;
for (int x = 0; x < a.length(); x++) {
if (a[x] == '9') {
nb[6]++;
} else if (a[x] == '5') {
nb[2]++;
} else {
nb[a[x] - '0']++;
}
}
for (int x = 0; x < 9; x++) {
if (na[x] > 0) {
c = min(c, nb[x] / na[x]);
}
}
cout << c << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, char_count;
int t_count = 1;
int array_of_numbers[10];
int possobilities[10];
for (int i = 0; i < 10; i++) {
array_of_numbers[i] = 0;
possobilities[i] = 0;
}
cin >> t;
string s;
cin >> s;
char_count = s.length();
for (int i = 0; i < char_count; i++) {
array_of_numbers[s[i] - '0']++;
}
int tmp = t;
while (tmp / 10 > 0) {
t_count++;
tmp = tmp / 10;
}
tmp = t;
int sequence[10];
for (int i = 0; i < 10; i++) {
sequence[i] = 0;
}
for (int i = 0; i < t_count; i++) {
sequence[tmp % 10]++;
tmp = tmp / 10;
}
for (int i = 0; i < 10; i++) {
}
for (int i = 0; i < 10; i++) {
}
int minans;
for (int i = 0; i < 10; i++) {
if (i == 9 || i == 5) {
} else {
if (sequence[i] != 0 ||
(sequence[i] == 0 && (i == 2 || i == 6) && sequence[i + 3] != 0)) {
if (i != 6 && i != 2)
possobilities[i] = array_of_numbers[i] / sequence[i];
else if (i == 6) {
possobilities[i] = (array_of_numbers[i] + array_of_numbers[9]) /
(sequence[i] + sequence[9]);
possobilities[9] = possobilities[i];
} else if (i == 2) {
possobilities[i] = (array_of_numbers[i] + array_of_numbers[5]) /
(sequence[i] + sequence[5]);
possobilities[5] = possobilities[i];
}
} else if (sequence[i] == 0) {
possobilities[i] = -1;
if ((i == 2 || i == 6) && sequence[i + 3] == 0)
possobilities[i + 3] = -1;
}
}
if (possobilities[i] > 0) minans = possobilities[i];
}
for (int i = 0; i < 10; i++) {
if (possobilities[i] != -1) {
if (minans > possobilities[i]) minans = possobilities[i];
}
}
cout << minans;
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.