text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxl = 10000 + 5; int res; int a[10], b[10]; int main() { char t[8], s[maxl]; scanf("%s%s", t, s); res = inf; for (int i = 0; t[i]; ++i) ++a[t[i] - '0']; for (int i = 0; s[i]; ++i) ++b[s[i] - '0']; 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 < 10; ++i) if (a[i] > 0) res = min(res, b[i] / a[i]); printf("%d\n", res); }
#include <bits/stdc++.h> using namespace std; int main() { string t, s; cin >> t >> s; vector<int> s1(10); vector<int> t1(10); for (int i = 0; i < 10; i++) { s1[i] = 0; t1[i] = 0; } int n = s.length(); for (int i = 0; i < n; i++) { s1[int(s[i]) - 48]++; } n = t.length(); for (int i = 0; i < n; i++) { t1[int(t[i]) - 48]++; } s1[2] += s1[5]; s1[5] = 0; s1[6] += s1[9]; s1[9] = 0; t1[2] += t1[5]; t1[5] = 0; t1[6] += t1[9]; t1[9] = 0; int ans = 2000; for (int i = 0; i < 10; i++) { if (t1[i] > 0 && (s1[i] / t1[i]) < ans) ans = s1[i] / t1[i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int Maxd = 10; const int Inf = 1000000000; int t; int need[Maxd]; int has[Maxd]; int res = Inf; int Conv(int x) { if (x == 9) x = 6; else if (x == 5) x = 2; return x; } void Take(int x) { while (x) { need[Conv(x % 10)]++; x /= 10; } } int main() { scanf("%d", &t); Take(t); string s; cin >> s; for (int i = 0; i < s.length(); i++) has[Conv(s[i] - '0')]++; for (int i = 0; i < Maxd; i++) if (need[i]) res = min(res, has[i] / need[i]); printf("%d\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string t, s; cin >> t; cin >> s; int a[10] = {0}, q[10] = {0}; int temp; for (auto i = 0; i < t.size(); i++) { temp = t[i] - '0'; if (temp == 2 || temp == 5) { a[2]++; } else if (temp == 6 || temp == 9) { a[6]++; } else { a[temp]++; } } for (auto i = 0; i < s.size(); i++) { temp = s[i] - '0'; if (temp == 2 || temp == 5) { q[2]++; } else if (temp == 6 || temp == 9) { q[6]++; } else { q[temp]++; } } int m = INFINITY; for (int i = 0; i < 10; i++) { if (a[i] != 0 && q[i] == 0) { cout << 0; return 0; } else if (a[i] != 0 && q[i] != 0) { temp = q[i] / a[i]; if (m > temp) { m = temp; } } } cout << m; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int i, k = 0, s = 0, ans = 0; string a, t; cin >> t; cin >> a; while (1) { k = 0; for (i = 0; i < a.length(); i++) { if (a[i] == t[s] || (t[s] == '5' && a[i] == '2') || (t[s] == '2' && a[i] == '5') || (t[s] == '6' && a[i] == '9') || (t[s] == '9' && a[i] == '6')) { a[i] = -1; k = 1; s++; } if (s == t.length()) { ans++; s = 0; break; } } if (k == 0) break; } cout << ans; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") using namespace std; bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); } void solve() { string t, str; cin >> t >> str; long long int ans = 2e9; map<long long int, long long int> hash1, hash2; for (long long int i = 0; i < t.size(); ++i) { long long int x = t[i] - '0'; if (x == 5) x = 2; else if (x == 9) x = 6; hash1[x]++; } for (long long int i = 0; i < str.size(); ++i) { long long int x = str[i] - '0'; if (x == 5) x = 2; else if (x == 9) x = 6; hash2[x]++; } for (auto i : hash1) ans = min(ans, hash2[i.first] / i.second); cout << ans; } int32_t main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T = 1; while (T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int a[10] = {}, b[10] = {}; string s, s1; cin >> s >> s1; for (int i = 0; i < s.size(); i++) { a[s[i] - '0']++; } for (int i = 0; i < s1.size(); i++) { b[s1[i] - '0']++; } a[2] += a[5]; a[5] = 0; b[2] += b[5]; b[5] = 0; a[6] += a[9]; a[9] = 0; b[6] += b[9]; b[9] = 0; int m = 999; for (int i = 0; i < 10; i++) { if (a[i] != 0) { if (b[i] / a[i] < m) m = b[i] / a[i]; } } cout << m; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { vector<int> a(10, 0), b(10, 0); string n; string num; cin >> n >> num; for (auto w : num) { a[w - '0']++; } int minimum = INT_MAX; for (auto w : n) b[w - '0']++; for (int i = 0; i < 10; i++) { if (i != 2 && i != 6 && i != 5 && i != 9 && b[i] > 0) minimum = min(minimum, a[i] / b[i]); } if (b[2] + b[5] > 0) minimum = min(minimum, (a[2] + a[5]) / (b[2] + b[5])); if (b[6] + b[9] > 0) minimum = min(minimum, (a[6] + a[9]) / (b[6] + b[9])); cout << minimum; return 0; }
#include <bits/stdc++.h> using namespace std; int req[10]; int poc[10]; int main() { int T; cin >> T; while (T > 0) { req[T % 10]++; T /= 10; } string s; cin >> s; for (int i = 0; i < s.length(); i++) poc[s[i] - '0']++; poc[9] += poc[6]; poc[2] += poc[5]; req[9] += req[6]; req[2] += req[5]; int ans = s.length(); for (int i = 0; i < 10; i++) if (i < 5 || i > 6) if (req[i] > 0) ans = min(ans, poc[i] / req[i]); cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n; int a[11], b[11]; char s[1111]; int main() { scanf("%d", &n); scanf("%s", s); while (n) b[n % 10]++, n /= 10; for (int i = 0; s[i]; i++) a[s[i] - '0']++; a[2] += a[5]; b[2] += b[5]; a[6] += a[9]; b[6] += b[9]; a[5] = a[9] = b[5] = b[9] = 0; int ret = 1111; for (int i = 0; i < 10; i++) if (b[i]) ret = min(ret, a[i] / b[i]); cout << ret << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[20], b[20]; char s[110000]; int main() { int n, i, j; scanf("%s", s); for (i = 0; s[i]; i++) { if (s[i] == '5') a[2]++; else if (s[i] == '9') a[6]++; else a[s[i] - '0']++; } scanf("%s", s); for (i = 0; s[i]; i++) { if (s[i] == '5') b[2]++; else if (s[i] == '9') b[6]++; else b[s[i] - '0']++; } int ans = 210000; for (i = 0; i <= 9; i++) if (i - 9 && i - 5) { if (a[i]) ans = min(ans, b[i] / a[i]); } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); map<char, int> index, req; string t, input; cin >> t >> input; for (int i = 0; input[i]; i++) { if (input[i] == '5') input[i] = '2'; else if (input[i] == '9') input[i] = '6'; index[input[i]]++; } for (int i = 0; t[i]; i++) { if (t[i] == '5') t[i] = '2'; else if (t[i] == '9') t[i] = '6'; req[t[i]]++; } int mn = INT_MAX; for (auto it = req.begin(); it != req.end(); it++) { int get = index[it->first] / it->second; mn = min(mn, get); } cout << mn << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long int dx[] = {1, -1, 0, 0}; long long int dy[] = {0, 0, -1, 1}; bool cmp(pair<long long int, long long int> a, pair<long long int, long long int> b) { return a.second - a.first + 1 < b.second - b.first + 1; } long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int power_mod(long long int a, long long int n) { long long int res = 1; while (n > 0) { if (n & 1) res = ((res % 1000000007) * (a % 1000000007)) % 1000000007, n--; else a = ((a % 1000000007) * (a % 1000000007)) % 1000000007, n /= 2; } return res; } long long int nCr(long long int n, long long int r) { if (r > n) return 0; double res = 1; for (long long int i = 1; i <= r; i++) res = (res * (n - r + i)) / i; return (long long int)(res + 0.01); } long long int power(long long int a, long long int n) { long long int res = 1; for (long long int i = 0; i < n; i++) res *= a; return res; } void solve() { string t, str; cin >> t >> str; long long int a[10]; long long int b[10]; for (long long int i = 0; i < 10; i++) a[i] = b[i] = 0; for (long long int i = 0; i < t.size(); i++) a[t[i] - '0']++; for (long long int i = 0; i < str.size(); i++) b[str[i] - '0']++; long long int ans = 0; bool flag = false; while (1) { for (long long int i = 0; i < 10; i++) { long long int x = a[i]; if (i == 2 || i == 5) { if (b[2] + b[5] < x) { flag = true; break; } else { if (b[2] >= x) b[2] -= x; else { x -= b[2]; b[2] = 0; b[5] -= x; } } } else if (i == 6 || i == 9) { if (b[6] + b[9] < x) { flag = true; break; } else { if (b[6] >= x) b[6] -= x; else { x -= b[6]; b[6] = 0; b[9] -= x; } } } else { if (b[i] >= x) b[i] -= x; else { flag = true; break; } } } if (flag) break; ans++; } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; vector<int> cnts(const string &s) { vector<int> ret(10, 0); for (int i = 0; i < (int)s.size(); ++i) { if (s[i] == '5') { ++ret[2]; } else if (s[i] == '9') { ++ret[6]; } else { ++ret[s[i] - '0']; } } return ret; } int main() { string num, have; cin >> num >> have; vector<int> a = cnts(num); vector<int> b = cnts(have); int sol = 1234567890; for (int i = 0; i < 10; ++i) { if (a[i] == 0) continue; sol = min(sol, b[i] / a[i]); } cout << sol << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; char a[300]; int p[10]; int t[10]; int main() { int input; cin >> input; if (input == 0) t[0]++; else while (input > 0) { t[input % 10]++; input /= 10; } cin >> a; for (int i = 0; a[i]; i++) p[a[i] - '0']++; t[2] += t[5]; t[5] = 0; t[6] += t[9]; t[9] = 0; p[2] += p[5]; p[5] = 0; p[6] += p[9]; p[9] = 0; int ans = 200; for (int i = 0; i < 10; i++) if (t[i]) if (p[i] / t[i] < ans) ans = p[i] / t[i]; cout << ans; }
#include <bits/stdc++.h> using namespace std; int ics[10]; int occ[10]; int main(void) { string t, str; cin >> t >> str; for (int i = 0; i < (int)str.length(); ++i) { ics[str[i] - '0']++; } for (int i = 0; i < (int)t.length(); ++i) { occ[t[i] - '0']++; } ics[6] = ics[6] + ics[9]; ics[2] = ics[2] + ics[5]; occ[6] = occ[6] + occ[9]; occ[2] = occ[2] + occ[5]; int mn = 100000000; for (int i = 0; i < (int)10; ++i) { if (i == 5 || i == 9 || occ[i] == 0) continue; int d = ics[i] / occ[i]; mn = (mn) < (d) ? (mn) : (d); } cout << mn << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int chkpower2(int x) { return (x && !(x & x - 1)); } void solve() { string s1, s2; cin >> s1 >> s2; map<char, int> m1, m2; for (int i1 = 0; i1 < s1.size(); i1++) { char ch1 = s1[i1]; if (s1[i1] == '9') { ch1 = '6'; } if (s1[i1] == '5') { ch1 = '2'; } if (m1.find(ch1) == m1.end()) { m1.insert(make_pair(ch1, 0)); } m1[ch1]++; } for (int i1 = 0; i1 < s2.size(); i1++) { char ch1 = s2[i1]; if (s2[i1] == '9') { ch1 = '6'; } if (s2[i1] == '5') { ch1 = '2'; } if (m2.find(ch1) == m2.end()) { m2.insert(make_pair(ch1, 0)); } m2[ch1]++; } int ans = 200; for (auto i : m1) { if (m2.find(i.first) == m2.end()) { cout << "0"; return; } int d1 = m2[i.first] / i.second; ans = min(ans, d1); } cout << ans; return; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; t = 1; while (t--) { solve(); cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int occ[2][10]; int main() { string a, b; cin >> a; cin >> b; for (int i = 0; i < a.size(); i++) { occ[0][a[i] - '0']++; } for (int i = 0; i < b.size(); i++) { occ[1][b[i] - '0']++; } for (int k = 0; k < 2; k++) { occ[k][2] += occ[k][5]; occ[k][5] = 0; occ[k][6] += occ[k][9]; occ[k][9] = 0; } int can = 100000000; for (int d = 0; d < 10; d++) { if (occ[0][d] != 0) can = min(can, occ[1][d] / occ[0][d]); } cout << can << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { string t; cin >> t; string s; cin >> s; int a[10] = {0}; map<int, int> m; for (int i = 0; i < s.size(); i++) { if (s[i] == '5') a[2]++; else if (s[i] == '9') a[6]++; else a[s[i] - '0']++; } for (int i = 0; i < t.size(); i++) { if (t[i] == '5') m[2]++; else if (t[i] == '9') m[6]++; else m[t[i] - '0']++; } int mn = s.size() + 1; for (auto it : m) { mn = min(mn, a[it.first] / it.second); } cout << mn; } int main() { int t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string t; cin >> t; string ice; cin >> ice; vector<long long int> arr(10, 0); for (long long int i = 0; i < ice.size(); i++) { if (ice[i] == '2' || ice[i] == '5') arr[2]++; else if (ice[i] == '6' || ice[i] == '9') arr[6]++; else arr[ice[i] - '0']++; } long long int ans = 0; long long int ind; vector<long long int> arr2(10, 0); for (long long int i = 0; i < t.size(); i++) { if (t[i] == '2' || t[i] == '5') { arr2[2]++; ind = 2; } else if (t[i] == '6' || t[i] == '9') { arr2[6]++; ind = 6; } else { arr2[t[i] - '0']++; ind = t[i] - '0'; } } long long int minn = 1000000007; for (long long int i = 0; i < 10; i++) { if (arr2[i] == 0) continue; else { if (arr[i] / arr2[i] < minn) minn = arr[i] / arr2[i]; } } cout << minn << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; vector<int> c, d; int flag = 0; vector<int> e(10, 0), f(10, 0); for (int i = 0; a[i] != '\0'; i++) { c.push_back((a[i]) - 48); e[c[i]]++; } for (int i = 0; b[i] != '\0'; i++) { d.push_back((b[i]) - 48); f[d[i]]++; } int mi = INT_MAX, dig; for (int i = 0; i < 10; i++) { if (i != 2 && i != 5 && i != 6 && i != 9) { if (e[i] > f[i]) flag = 1; if (e[i] > 0) { f[i] /= e[i]; } } } if (flag) { cout << "0"; return 0; } else { e[2] += e[5]; e[5] = e[2]; e[6] += e[9]; e[9] = e[6]; f[2] += f[5]; f[6] += f[9]; if (e[2] > 0) f[2] /= e[2]; if (e[6] > 0) f[6] /= e[6]; f[5] = f[2]; f[9] = f[6]; for (int i = 0; i < 10; i++) { if (e[i] > 0 && f[i] < mi) { mi = f[i]; } } cout << mi; } return 0; }
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1.0); const long double eps = 1e-9; const long long mod = (1e+9) + 7ll; bool u[201]; string s, t; int main() { cin >> s >> t; int cc = 0; while (1) { for (int i = 0; i < s.length(); ++i) { int f = 0; for (int j = 0; j < t.length(); ++j) { bool fl = 0; fl = ((s[i] == '6' || s[i] == '9') && (t[j] == '6' || t[j] == '9')); fl = fl | ((s[i] == '2' || s[i] == '5') && (t[j] == '2' || t[j] == '5')); fl = fl | (s[i] == t[j]); if (fl && !u[j]) { u[j] = 1; f = 1; break; } } if (!f) { cout << cc; return 0; } } cc++; } cout << cc; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; char b[500]; while (cin >> n) { int c; int a[20] = {0}; while (n > 0) { c = n % 10; n = n / 10; a[c] = a[c] + 1; } cin >> b; int len = strlen(b); int i = 0; while (i < len) { a[b[i] - '0' + 10] += 1; i = i + 1; } int z = 0; int s = 0; while (z == 0) { i = 0; while (i < 10) { if ((a[10 + i] < a[i]) && ((i == 2) || (i == 5) || (i == 6) || (i == 9))) { if (i == 2) { a[12] = a[12] + a[15]; a[15] = 0; } else if (i == 5) { a[15] = a[12] + a[15]; a[12] = 0; } else if (i == 6) { a[16] = a[16] + a[19]; a[19] = 0; } else if (i == 9) { a[19] = a[19] + a[16]; a[16] = 0; } } a[10 + i] -= a[i]; if (a[10 + i] < 0) z = 1; i = i + 1; } if (z == 0) s = s + 1; } cout << s << endl; } }
#include <bits/stdc++.h> using namespace std; using namespace std; const int N = 220; const int INF = 1 << 30; char a[10]; char b[N]; int cnta[10]; int cntb[10]; int main() { scanf("%s", a); scanf("%s", b); int na = strlen(a); int nb = strlen(b); for (int i = 0; i < na; ++i) { if (a[i] == '5') ++cnta[2]; else if (a[i] == '9') ++cnta[6]; else ++cnta[a[i] - '0']; } for (int i = 0; i < nb; ++i) { if (b[i] == '5') ++cntb[2]; else if (b[i] == '9') ++cntb[6]; else ++cntb[b[i] - '0']; } int x = INF; for (int i = 0; i < 10; ++i) { if (cnta[i] > 0) x = min(x, cntb[i] / cnta[i]); } cout << x << endl; }
#include <bits/stdc++.h> int main() { char ch[222]; int a[10] = {0}, b[10] = {0}; int sum = 0, i; scanf("%s", ch); for (i = 0; i < strlen(ch); i++) { if (ch[i] - '0' == 5) a[2]++; else if (ch[i] - '0' == 9) a[6]++; else a[(ch[i] - '0')]++; } scanf("%s", ch); for (i = 0; i < strlen(ch); i++) { if (ch[i] - '0' == 5) b[2]++; else if (ch[i] - '0' == 9) b[6]++; else b[(ch[i] - '0')]++; } int sign = 1; while (sign) { for (i = 0; i < 10; i++) { if (b[i] - a[i] >= 0) { b[i] -= a[i]; continue; } else { sign = 0; break; } } if (i == 10) sum++; } printf("%d\n", sum); return 0; }
#include <bits/stdc++.h> using namespace std; template <class telem> telem MAX(telem a, telem b) { return (a > b) ? a : b; } template <class telem> telem MIN(telem a, telem b) { return (a < b) ? a : b; } template <class telem> telem GCD(telem a, telem b) { return b ? GCD(b, a % b) : a; } template <class telem> telem LCM(telem a, telem b) { return a / GCD(a, b) * b; } template <class telem> telem UNSIGNED(telem a) { return (a > 0) ? a : a * (-1); } template <class telem> void bez_swop(telem &a, telem &b) { telem c = a; a = b; b = c; } void swop(int &a, int &b) { a = a ^ b; b = a ^ b; a = a ^ b; } int mas[10], tmp[10], r, rez; int main() { int i; char c; c = getchar(); while ((c != EOF && c != '\0' && c != '\n' && c != ' ')) { switch (c) { case '0': tmp[0]++; break; case '1': tmp[1]++; break; case '2': tmp[2]++; break; case '3': tmp[3]++; break; case '4': tmp[4]++; break; case '5': tmp[2]++; break; case '6': tmp[6]++; break; case '7': tmp[7]++; break; case '8': tmp[8]++; break; case '9': tmp[6]++; break; } c = getchar(); } c = getchar(); while ((c != EOF && c != '\0' && c != '\n' && c != ' ')) { switch (c) { case '0': mas[0]++; break; case '1': mas[1]++; break; case '2': mas[2]++; break; case '3': mas[3]++; break; case '4': mas[4]++; break; case '5': mas[2]++; break; case '6': mas[6]++; break; case '7': mas[7]++; break; case '8': mas[8]++; break; case '9': mas[6]++; break; } c = getchar(); } for (i = 0, rez = 1000000005; i < 10; i++) { if (tmp[i]) { r = mas[i] / tmp[i]; rez = MIN(rez, r); } } printf("%d", rez); return 0; }
#include <bits/stdc++.h> using namespace std; int t[10]; int u[10]; int main() { int c; while (true) { c = getchar(); if (c < '0' || c > '9') break; if (c == '5') c = '2'; if (c == '9') c = '6'; ++t[c - '0']; } while (c < '0' || c > '9') c = getchar(); while (true) { if (c == '5') c = '2'; if (c == '9') c = '6'; ++u[c - '0']; c = getchar(); if (c < '0' || c > '9') break; } int minCnt = INT_MAX; for (int i = 0; i < 10; i++) { if (t[i] == 0) continue; int cnt = u[i] / t[i]; if (cnt < minCnt) minCnt = cnt; } printf("%d\n", minCnt); return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { string s1, s2; cin >> s1 >> s2; map<char, long long> m1, m2; long long i; for (i = 0; i < s1.length(); i++) { if (s1[i] == '9') s1[i] = '6'; if (s1[i] == '5') s1[i] = '2'; m1[s1[i]]++; } for (i = 0; i < s2.length(); i++) { if (s2[i] == '9') s2[i] = '6'; if (s2[i] == '5') s2[i] = '2'; m2[s2[i]]++; } long long ans = INT_MAX; for (auto it : m1) { ans = min(ans, m2[it.first] / m1[it.first]); } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; string fav, input; int need[9], have[9], res; int main() { cin >> fav; cin >> input; for (int i = 0; i < fav.length(); i++) { if (fav[i] == '1') need[1]++; if (fav[i] == '2') need[2]++; if (fav[i] == '3') need[3]++; if (fav[i] == '4') need[4]++; if (fav[i] == '5') need[2]++; if (fav[i] == '6') need[6]++; if (fav[i] == '7') need[7]++; if (fav[i] == '8') need[8]++; if (fav[i] == '9') need[6]++; if (fav[i] == '0') need[0]++; } for (int i = 0; i < input.length(); i++) { if (input[i] == '1') have[1]++; if (input[i] == '2') have[2]++; if (input[i] == '3') have[3]++; if (input[i] == '4') have[4]++; if (input[i] == '5') have[2]++; if (input[i] == '6') have[6]++; if (input[i] == '7') have[7]++; if (input[i] == '8') have[8]++; if (input[i] == '9') have[6]++; if (input[i] == '0') have[0]++; } res = input.length() / fav.length(); for (int i = 0; i <= 8; i++) { if (need[i] != 0 && have[i] == 0) res = 0; if (need[i] != 0 && have[i] != 0) res = min(res, have[i] / need[i]); } cout << res; }
#include <bits/stdc++.h> using namespace std; int main() { int need[12], supply[12], count[12]; char fav[10], given[220]; int i, j; cin >> fav; cin >> given; memset(need, 0, sizeof(need)); for (i = 0; fav[i] != '\0'; ++i) { need[fav[i] - '0']++; } need[2] += need[5]; need[6] += need[9]; memset(supply, 0, sizeof(supply)); for (i = 0; given[i] != '\0'; ++i) { supply[given[i] - '0']++; } supply[2] += supply[5]; supply[6] += supply[9]; memset(count, 0, sizeof(count)); int min = 0x7FFFFFFF; for (i = 0; i <= 9; ++i) { if (i == 5 || i == 9 || need[i] == 0) continue; count[i] = supply[i] / need[i]; if (count[i] < min) min = count[i]; } cout << min << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; bool is(char x, char y) { if ((x == '2' || x == '5') && (y == '2' || y == '5')) return true; if ((x == '6' || x == '9') && (y == '6' || y == '9')) return true; if (x == y) return true; return false; } void solve() { string s, t; cin >> s >> t; vector<bool> used(t.size(), false); int cnt = 0; while (true) { bool q = true; for (int i = 0; i < s.size(); i++) { bool w = false; for (int j = 0; j < t.size(); j++) { if (used[j]) continue; if (is(s[i], t[j])) { used[j] = true; w = true; break; } } if (!w) { q = false; break; } } if (!q) break; cnt++; } cout << cnt; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t = 1; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; int main() { char t[300], a[300]; scanf("%s", &t); scanf("%s", &a); char p[300]; int n = strlen(t), m = strlen(a); fill(p, p + 300, 0); int cnt[10], cnt2[10]; fill(cnt, cnt + 10, 0); fill(cnt2, cnt2 + 10, 0); for (int i = 0; i < n; i++) { if (t[i] == '5') t[i] = '2'; if (t[i] == '9') t[i] = '6'; cnt[t[i] - 48]++; } for (int i = 0; i < m; i++) { if (a[i] == '5') a[i] = '2'; if (a[i] == '9') a[i] = '6'; cnt2[a[i] - 48]++; } int ans = 0; for (int i = 0; i < 10; i++) if (cnt[i] != 0) { if (ans == 0) ans = cnt2[i] / cnt[i]; else ans = min(ans, cnt2[i] / cnt[i]); } printf("%d", ans); }
#include <bits/stdc++.h> using namespace std; int ans, t[10], ok = 1; char n[10], m[205]; int main() { cin >> n >> m; for (int i = 0; i < strlen(m); i++) { if (m[i] == '5') t[2]++; else if (m[i] == '9') t[6]++; else t[m[i] - '0']++; } while (ok) { for (int i = 0; i < strlen(n); i++) { if (n[i] == '5') { if (t[2] > 0) t[2]--; else ok = 0; } else if (n[i] == '9') { if (t[6] > 0) t[6]--; else ok = 0; } else { if (t[n[i] - '0'] > 0) t[n[i] - '0']--; else ok = 0; } } if (ok == 1) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t, a[10] = {0}, b[10] = {0}, sum = 0; string s; cin >> t >> s; while (t > 0) { a[t % 10]++; t /= 10; } a[2] += a[5]; a[5] = 0; a[6] += a[9]; a[9] = 0; for (int i = 0; i < s.size(); i++) b[s[i] - '0']++; b[2] += b[5]; b[5] = 0; b[6] += b[9]; b[9] = 0; int ans = 99999; for (int i = 0; i < 9; i++) if (a[i] && b[i]) ans = min(ans, b[i] / a[i]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s, l; cin >> s >> l; int szs = s.length(); int szl = l.length(); int as[10] = {0}; int al[10] = {0}; for (int i = 0; i < szs; i++) { if (s[i] == '6' || s[i] == '9') as[6]++; else if (s[i] == '2' || s[i] == '5') as[2]++; else if (s[i] == '1') as[1]++; else if (s[i] == '0') as[0]++; else if (s[i] == '3') as[3]++; else if (s[i] == '4') as[4]++; else if (s[i] == '7') as[7]++; else if (s[i] == '8') as[8]++; } for (int i = 0; i < szl; i++) { if (l[i] == '6' || l[i] == '9') al[6]++; else if (l[i] == '2' || l[i] == '5') al[2]++; else if (l[i] == '1') al[1]++; else if (l[i] == '0') al[0]++; else if (l[i] == '3') al[3]++; else if (l[i] == '4') al[4]++; else if (l[i] == '7') al[7]++; else if (l[i] == '8') al[8]++; } for (int i = 0; i < 10; i++) { if (as[i] == 0) al[i] = 10001; else al[i] = al[i] / as[i]; } int mi = 100000; for (int i = 0; i < 10; i++) { if (al[i] < mi) mi = al[i]; } cout << mi; }
#include <bits/stdc++.h> using namespace std; int main() { vector<char> pieces, puzzle; string X, Y; cin >> X >> Y; for (int i = 0; i < X.size(); i++) puzzle.push_back(X.at(i)); for (int i = 0; i < Y.size(); i++) pieces.push_back(Y.at(i)); sort(pieces.begin(), pieces.end()); int count = 0, i = 0; while (true) { if (binary_search(pieces.begin(), pieces.end(), puzzle[i])) { pieces.erase(lower_bound(pieces.begin(), pieces.end(), puzzle[i])); i++; } else if (puzzle[i] == '6') { if (binary_search(pieces.begin(), pieces.end(), '9')) { pieces.erase(lower_bound(pieces.begin(), pieces.end(), '9')); i++; } else break; } else if (puzzle[i] == '9') { if (binary_search(pieces.begin(), pieces.end(), '6')) { pieces.erase(lower_bound(pieces.begin(), pieces.end(), '6')); i++; } else break; } else if (puzzle[i] == '2') { if (binary_search(pieces.begin(), pieces.end(), '5')) { pieces.erase(lower_bound(pieces.begin(), pieces.end(), '5')); i++; } else break; } else if (puzzle[i] == '5') { if (binary_search(pieces.begin(), pieces.end(), '2')) { pieces.erase(lower_bound(pieces.begin(), pieces.end(), '2')); i++; } else break; } else { break; } if (i == puzzle.size()) { i = 0; count++; } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long A = 100000000000000LL, N = 228228; string a, b; long long l, r, p, c[3][10], i, j, n, m; int check(long long a) { for (i = 0; i < 10; i++) c[2][i] = c[1][i] - c[0][i] * a; for (i = 0; i < 10; i++) if (c[2][i] < 0 && i != 6 && i != 2 && i != 5 && i != 9) return 0; ; if (c[2][6] + c[2][9] < 0) return 0; ; if (c[2][2] + c[2][5] < 0) return 0; ; return 1; } int main() { cin >> a, n = a.size(); cin >> b, m = b.size(); for (i = 0; i < n; i++) c[0][a[i] - '0']++; for (i = 0; i < m; i++) c[1][b[i] - '0']++; l = 0, r = m; while (r - l > 1) { p = (l + r) / 2; if (check(p)) l = p; else r = p; } if (check(r)) cout << r; else cout << l; }
#include <bits/stdc++.h> using namespace std; int main() { int a[20], b[20], ans = 1e9; char c[10], d[210]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); cin >> c >> d; for (int i = 0; i < strlen(c); i++) a[c[i] - '0']++; a[6] += a[9]; a[9] = a[6]; a[2] += a[5]; a[5] = a[2]; for (int i = 0; i < strlen(d); i++) { if (d[i] == '9' || d[i] == '6') { b[6]++; b[9]++; } else if (d[i] == '2' || d[i] == '5') { b[2]++; b[5]++; } else b[d[i] - '0']++; } 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; bool sortbyfir(const pair<int, int> &a, const pair<int, int> &b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { if (a.second == b.second) return a.first < b.first; return (a.second < b.second); } bool sr(const pair<int, int> &a, const pair<int, int> &b) { if (a.first == b.first) return a.second > b.second; else return a.first < b.first; } bool compmx(int a, int b) { return (a < b); } long long int binaryToDecimal(string n) { string num = n; long long int dec_value = 0; long long int base = 1; for (int i = num.length() - 1; i >= 0; i--) { if (num[i] == '1') dec_value += base; base = base * 2; } return dec_value; } string decimalToBinary(long long int n) { string s = bitset<64>(n).to_string(); const auto loc1 = s.find('1'); if (loc1 != string::npos) return s.substr(loc1); return "0"; } long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return (a / gcd(a, b)) * b; } bool is_prime(long long int x) { if (x == 1) return false; if (x == 2 || x == 3) return true; for (long long int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } bool isp(string str) { int l = 0, h = str.length() - 1; while (h > l) if (str[l++] != str[h--]) return false; return true; } long long int power(long long int a, long long int b) { long long int res = 1ll; while (b > 0) { if (b % 2ll) res = (res * a) % 1000000007; ; a = (a * a) % 1000000007; ; b /= 2ll; } return res; } long long int interact(long long int i) { cout << i << "\n"; cout.flush(); long long int ret; cin >> ret; cout.flush(); return ret; } vector<long long int> primes; void getPrimes() { vector<bool> p(1001, true); for (long long int i = 2; i * i <= 1000; i++) { if (p[i]) { for (long long int j = i * i; j <= 1000; j += i) { p[j] = false; } } } for (long long int i = 2; i <= 1000; i++) { if (p[i]) { primes.push_back(i); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string t, s; cin >> t >> s; long long int nt = t.length(); long long int ns = s.length(); vector<long long int> a(10, 0), b(10, 0); for (long long int i = 0; i < ns; i++) { if (s[i] == '5') a[2]++; else if (s[i] == '9') a[6]++; else a[s[i] - '0']++; } for (long long int i = 0; i < nt; i++) { if (t[i] == '5') b[2]++; else if (t[i] == '9') b[6]++; else b[t[i] - '0']++; } long long int ans = INT_MAX; for (long long int i = 0; i < 10; i++) { if (b[i]) { ans = min(ans, a[i] / b[i]); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> int main(int argc, char** argv) { char innum[1000] = {0}; char testnum[1000] = {0}; char c; int num[100] = {0}; int map[100] = {0}; int len, len2, i, res, min = 99999; scanf("%s", innum); scanf("%s", testnum); len = strlen(innum); for (i = 0; i < len; i++) { c = innum[i] - '0'; if (c == 5 || c == 2) map[2]++; else if (c == 9 || c == 6) map[6]++; else map[c]++; } len2 = strlen(testnum); for (i = 0; i < len2; i++) { c = testnum[i] - '0'; if (c == 5 || c == 2) num[2]++; else if (c == 9 || c == 6) num[6]++; else num[c]++; } for (i = 0; i < 10; i++) { if (map[i]) { num[i] = num[i] / map[i]; if (min > num[i]) min = num[i]; } } printf("%d\n", min); return 0; }
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); char s[202]; scanf("%s", s); int len = strlen(s); int digit[10], want[10], ans[10]; for (int i = 0; i < 10; i++) { digit[i] = 0; want[i] = 0; ans[i] = 0; } for (int i = 0; i < len; i++) { if (s[i] == '0') digit[0]++; if (s[i] == '1') digit[1]++; if (s[i] == '2') digit[2]++; if (s[i] == '3') digit[3]++; if (s[i] == '4') digit[4]++; if (s[i] == '5') digit[2]++; if (s[i] == '6') digit[6]++; if (s[i] == '7') digit[7]++; if (s[i] == '8') digit[8]++; if (s[i] == '9') digit[6]++; } int r; while (t > 0) { r = t % 10; want[r]++; t /= 10; } want[2] += want[5]; want[6] += want[9]; for (int i = 0; i < 10; i++) { if (want[i] > 0 && i != 5 && i != 9) { ans[i] = digit[i] / want[i]; } } int min = 10000; for (int i = 0; i < 10; i++) { if (want[i] > 0 && i != 5 && i != 9) { if (ans[i] < min) min = ans[i]; } } printf("%d\n", min); return 0; }
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); } int n, m; string a, b; vector<int> va(10), vb(10); int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> a >> b; n = a.size(); m = b.size(); for (int i = 0; i < n; i++) va[a[i] - '0']++; va[2] += va[5]; va[6] += va[9]; for (int i = 0; i < m; i++) vb[b[i] - '0']++; vb[2] += vb[5]; vb[6] += vb[9]; int ans = 0x3f3f3f3f; for (int i = 0; i <= 9; i++) { if (i == 5 || i == 9) continue; if (va[i]) ans = min(ans, vb[i] / va[i]); } cout << (ans == 0x3f3f3f3f ? 0 : ans) << "\n"; }
#include <bits/stdc++.h> using namespace std; int t, a[10], b[10]; int main() { int i, j, k; cin >> t; while (t > 0) { k = t % 10; a[k]++; t /= 10; } string s; cin >> s; for (i = 0; i < s.size(); i++) { b[s[i] - '0']++; } a[6] += a[9], a[2] += a[5]; a[9] = 0, a[5] = 0; b[6] += b[9], b[2] += b[5]; b[9] = 0, b[5] = 0; int min = 999999; for (i = 0; i <= 9; i++) if (a[i] != 0) { k = b[i] / a[i]; if (k < min) min = k; } cout << min << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int tot[15], num[15]; string t, now; int main() { cin >> t >> now; int len = t.size(); for (int i = 0; i < len; i++) num[t[i] - '0']++; num[2] += num[5], num[5] = 0; num[6] += num[9], num[9] = 0; len = now.size(); for (int i = 0; i < len; i++) tot[now[i] - '0']++; tot[2] += tot[5], tot[5] = 0; tot[6] += tot[9], tot[9] = 0; int ans = INT_MAX; for (int i = 0; i <= 9; i++) { if (num[i] == 0) continue; ans = min(ans, tot[i] / num[i]); } cout << ans; return 0; }
#include <bits/stdc++.h> int min(int a, int b) { if (a < b) return a; return b; } int main() { char ice[201]; int tnum[10] = { 0, }, num[10] = { 0, }, i, t, cnt = 10000000; scanf("%d%s", &t, ice); for (i = 0; i < strlen(ice); i++) { num[(int)(ice[i] - 48)]++; } while (t) { tnum[t % 10]++; t /= 10; } num[2] += num[5]; num[6] += num[9]; tnum[2] += tnum[5]; tnum[6] += tnum[9]; for (i = 0; i < 10; i++) { if (tnum[i] && i != 5 && i != 9) cnt = min(cnt, num[i] / tnum[i]); } printf("%d", cnt); return 0; }
#include <bits/stdc++.h> using namespace std; string t, s; int l; int a[33]; int b[33]; int main() { int n, i, min = 99999999; cin >> t >> s; n = s.size(); for (i = 0; i < 10; i++) { a[i] = 0; b[i] = 0; } for (i = 0; i < n; i++) { if (s[i] == '9') s[i] = '6'; else if (s[i] == '5') s[i] = '2'; b[s[i] - '0']++; } l = t.size(); for (i = 0; i < l; i++) { if (t[i] == '9') t[i] = '6'; else if (t[i] == '5') t[i] = '2'; a[t[i] - '0']++; } for (i = 0; i < 10; i++) { if (a[i] > 0) { if (b[i] / a[i] < min) min = b[i] / a[i]; } } cout << min << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string t; int need[10]; for (int i = 0; i <= 9; i++) need[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; int have[10]; for (int i = 0; i <= 9; i++) have[i] = 0; 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; bool all_ones(int a[]) { for (int i = 0; i < 10; i++) if (a[i] != 1) return false; return true; } int min_count(int a[], int b[]) { int min = INT_MAX; for (int i = 0; i < 10; i++) if (a[i] && b[i] && a[i] < min) min = a[i]; return min; } int main() { string target, pieces; cin >> target >> pieces; int count_target[10], count_pieces[10]; for (int i = 0; i < 10; i++) count_target[i] = count_pieces[i] = 0; for (int i = 0; i < target.size(); i++) { if (target[i] == '5') count_target[2]++; else if (target[i] == '9') count_target[6]++; else count_target[target[i] - 48]++; } for (int i = 0; i < pieces.size(); i++) { if (pieces[i] == '5') count_pieces[2]++; else if (pieces[i] == '9') count_pieces[6]++; else count_pieces[pieces[i] - 48]++; } if (all_ones(count_target)) cout << min_count(count_pieces, count_target) << endl; else { int min = INT_MAX; for (int i = 0; i < 10; i++) { if (count_target[i]) { int ratio = count_pieces[i] / count_target[i]; if (ratio < min) min = ratio; } } cout << min << endl; } return 0; }
#include <bits/stdc++.h> char a[200], b[200]; int p[10], q[10]; int main() { int i, j; for (i = 0; i < 10; i++) p[i] = q[i] = 0; scanf("%s %s", a, b); for (i = 0; a[i]; i++) { if (a[i] == '2') p[5]++; else if (a[i] == '6') p[9]++; else p[a[i] - '0']++; } for (i = 0; b[i]; i++) { if (b[i] == '2') q[5]++; else if (b[i] == '6') q[9]++; else q[b[i] - '0']++; } j = 999999999; for (i = 0; i < 10; i++) { if (p[i]) { if (q[i] / p[i] < j) j = q[i] / p[i]; } } printf("%d\n", j); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string t; string st; cin >> t >> st; map<int, int> mpt; map<int, int> mpst; int i; int mini = INT_MAX; int sum = 0; set<int> s; for (i = 0; i < t.length(); i++) { if (t[i] == '5') t[i] = '2'; if (t[i] == '9') t[i] = '6'; } for (i = 0; i < st.length(); i++) { if (st[i] == '5') st[i] = '2'; if (st[i] == '9') st[i] = '6'; } for (i = 0; i < t.length(); i++) { mpt[t[i] - '0']++; s.insert(t[i] - '0'); } for (i = 0; i < st.length(); i++) mpst[st[i] - '0']++; for (set<int>::iterator itr = s.begin(); itr != s.end(); itr++) { mpst[*itr] = mpst[*itr] / mpt[*itr]; } for (set<int>::iterator itr = s.begin(); itr != s.end(); itr++) { if (mpst[*itr] < mini) { mini = mpst[*itr]; } } cout << mini << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n[10] = {0}, m[10] = {0}, k, ans = -1; string num, s; cin >> num >> s; for (int i = 0; i < (int)(s.size()); i++) { if (s[i] - '0' == 5) n[2]++; else if (s[i] - '0' == 9) n[6]++; else n[s[i] - '0']++; } for (int i = 0; i < (int)(num.size()); i++) { if (num[i] - '0' == 5) m[2]++; else if (num[i] - '0' == 9) m[6]++; else m[num[i] - '0']++; } for (int i = 0; i < 10; i++) { if (m[i] && n[i] && (ans > n[i] / m[i] || ans == -1)) ans = n[i] / m[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string a; getline(cin, a); string b; getline(cin, b); vector<char> numberstokeeptrackof; map<char, int> legit; map<char, int> inventory; for (int g = 0; g < a.length(); g++) { if (legit[a[g]] == 0) { if (a[g] == '9') { numberstokeeptrackof.push_back('6'); } else if (a[g] == '5') { numberstokeeptrackof.push_back('2'); } else { numberstokeeptrackof.push_back(a[g]); } } if (a[g] == '6' || a[g] == '9') { legit['6'] += 1; } else if (a[g] == '5' || a[g] == '2') { legit['2'] += 1; } else { legit[a[g]] += 1; } } for (int g = 0; g < b.length(); g++) { if (b[g] == '6' || b[g] == '9') { inventory['6'] += 1; } else if (b[g] == '2' || b[g] == '5') { inventory['2'] += 1; } else { inventory[b[g]] += 1; } } long long min = 100000000000; for (int g = 0; g < numberstokeeptrackof.size(); g++) { if (floor(inventory[numberstokeeptrackof[g]] / legit[numberstokeeptrackof[g]]) < min) { min = floor(inventory[numberstokeeptrackof[g]] / legit[numberstokeeptrackof[g]]); } } cout << min; }
#include <bits/stdc++.h> using namespace std; int a[20], b[20]; int find(int n) { if (n == 5) return 2; if (n == 9) return 6; return n; } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; memset(a, sizeof(a), 0); while (n > 0) { int h = find(n % 10); n /= 10; a[h]++; } memset(b, sizeof(b), 0); string s; cin >> s; for (int i = 0; i < s.size(); i++) { int h = s[i] - '0'; h = find(h); b[h]++; } int answer = 1000000000; for (int i = 0; i <= 9; i++) if (a[i] > 0) answer = min(answer, b[i] / a[i]); cout << answer << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char a[210], b[210]; scanf("%s %s", a, b); int na = strlen(a), nb = strlen(b); int reva[11] = {0}, revb[11] = {0}; for (int i = int(0); i < int(na); i++) { if (a[i] == '2') reva[5]++; else if (a[i] == '6') reva[9]++; else reva[a[i] - '0']++; } for (int i = int(0); i < int(nb); i++) { if (b[i] == '2') revb[5]++; else if (b[i] == '6') revb[9]++; else revb[b[i] - '0']++; } bool sw = false; int mini = 999999; for (int i = int(0); i < int(10); i++) { if (revb[i] == 0 && reva[i] > 0) { sw = true; break; } else { if (revb[i] > 0 && reva[i] > 0) mini = min(mini, revb[i] / reva[i]); } } if (sw) puts("0"); else cout << mini << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string t, s; int N, M, Ans, G[11], F[11], fa[11]; void work() { for (int i = (0), _n = (9); i <= _n; i++) fa[i] = i; fa[5] = 2, fa[9] = 6; N = s.size(); M = t.size(); memset(G, 0, sizeof(G)); for (int i = (0), _n = (N - 1); i <= _n; i++) G[fa[s[i] - 48]]++; memset(F, 0, sizeof(F)); for (int i = (0), _n = (M - 1); i <= _n; i++) F[fa[t[i] - 48]]++; Ans = N; for (int i = (0), _n = (9); i <= _n; i++) if (F[i]) Ans = min(Ans, G[i] / F[i]); printf("%d\n", Ans); } int main() { cin >> t; cin >> s; work(); return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 3e5 + 10; int a[N]; void check(string& s, map<char, int>& mc) { for (auto& c : s) { if (c == '5') c = '2'; if (c == '9') c = '6'; mc[c]++; } } int main() { string str1; string str2; map<char, int> mc1, mc2; cin >> str1 >> str2; check(str1, mc1); check(str2, mc2); int ans = INF; for (auto& p : mc1) { ans = min(ans, mc2[p.first] / p.second); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int c1[10], c2[10]; char s[222]; int main() { while (cin >> s) { memset(c1, 0, sizeof(c1)); memset(c2, 0, sizeof(c2)); int l = strlen(s); for (int i = 0; i < l; i++) c1[s[i] - '0']++; c1[2] += c1[5]; c1[6] += c1[9]; c1[5] = c1[9] = 0; cin >> s; l = strlen(s); for (int i = 0; i < l; i++) c2[s[i] - '0']++; c2[2] += c2[5]; c2[6] += c2[9]; c2[5] = c2[9] = 0; int ans = 222; for (int i = 0; i < 10; i++) { if (c1[i] == 0) continue; ans = min(c2[i] / c1[i], ans); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; string a, b; int ans, need[11], num[11]; int main() { cin >> a >> b; for (int i = 0; i < a.length(); i++) { if ((a[i] != '2') && (a[i] != '5') && (a[i] != '6') && (a[i] != '9')) { need[a[i] - '0']++; } else if (a[i] == '2' || a[i] == '5') { need[2]++; } else { need[6]++; } } for (int i = 0; i < b.length(); i++) { if ((b[i] != '2') && (b[i] != '5') && (b[i] != '6') && (b[i] != '9')) { num[b[i] - '0']++; } else if (b[i] == '2' || b[i] == '5') { num[2]++; } else { num[6]++; } } ans = 9999; for (int i = 0; i <= 9; i++) { if (need[i] != 0) { ans = min(ans, num[i] / need[i]); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } int thas[30], shas[30]; int main() { string t, s; cin >> t >> s; for (int i = 0; i < t.size(); i++) { if (t[i] == '9') t[i] = '6'; if (t[i] == '5') t[i] = '2'; thas[t[i] - '0']++; } for (int i = 0; i < s.size(); i++) { if (s[i] == '9') s[i] = '6'; if (s[i] == '5') s[i] = '2'; shas[s[i] - '0']++; } int mn = INT_MAX; for (int i = 0; i <= 9; i++) { if (thas[i] == 0) continue; if (thas[i] > shas[i]) { mn = 0; break; } mn = min(mn, shas[i] / thas[i]); } cout << mn; return 0; }
#include <bits/stdc++.h> using namespace std; char s1[1000], s2[1000]; int num[100], tot[100]; int main() { scanf("%s", s1); for (int i = 0; s1[i]; i++) { if (s1[i] == '6' || s1[i] == '9') { num[6]++; } else if (s1[i] == '2' || s1[i] == '5') { num[2]++; } else { num[s1[i] - '0']++; } } scanf("%s", s2); for (int i = 0; s2[i]; i++) { if (s2[i] == '6' || s2[i] == '9') { tot[6]++; } else if (s2[i] == '2' || s2[i] == '5') { tot[2]++; } else { tot[s2[i] - '0']++; } } int ans = 100000; for (int i = 0; i <= 9; i++) { if (i == 9 || i == 5) continue; if (!num[i]) continue; ans = min(ans, tot[i] / num[i]); } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; string s, t; int a[15], b[15], ans = 1000; int main() { cin >> t >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == '6' || s[i] == '9') { a[6]++; continue; } if (s[i] == '2' || s[i] == '5') { a[2]++; continue; } a[s[i] - '0']++; } for (int i = 0; i < t.length(); i++) { if (t[i] == '6' || t[i] == '9') { b[6]++; continue; } if (t[i] == '2' || t[i] == '5') { b[2]++; continue; } b[t[i] - '0']++; } for (int i = 0; i < 9; i++) if (i != 5 && b[i] != 0) ans = min(ans, a[i] / b[i]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a[20], b[20], ans = 1e9; char c[100010], d[100010]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); cin >> c >> d; for (int i = 0; i < strlen(c); i++) a[c[i] - '0']++; a[6] += a[9]; a[2] += a[5]; for (int i = 0; i < strlen(d); i++) { if (d[i] == '9' || d[i] == '6') { b[6]++; b[9]++; } else if (d[i] == '2' || d[i] == '5') { b[2]++; b[5]++; } else b[d[i] - '0']++; } for (int i = 0; i < 10; 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() { int t; string s; cin >> t; cin >> s; int num[10] = {0}; int arr[10] = {0}; int temp = t; while (temp > 0) { if (temp % 10 == 9) { num[6] += 1; } else if (temp % 10 == 5) { num[2] += 1; } else { num[temp % 10] += 1; } temp /= 10; } vector<int> dig; for (int i = 0; i < 10; i++) { if (num[i] != 0) { dig.push_back(i); } } for (int i = 0; i < s.size(); i++) { int x = s[i] - '0'; if (x == 2 || x == 5) arr[2] += 1; else if (x == 6 || x == 9) arr[6] += 1; else arr[x] += 1; } int ans = 0; bool cont = true; while (cont) { for (int i : dig) { int req = num[i]; int hav = arr[i]; if (req > hav) { cont = false; break; } else { arr[i] -= req; } } if (cont) ans += 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); set<int> s; string t, k; cin >> t; int jj; for (int i = 0; i < t.length(); i++) { if (t[i] != ',') { k += t[i]; } else { jj = stoi(k); s.insert(jj); k.clear(); } } jj = stoi(k); s.insert(jj); vector<int> v(s.begin(), s.end()); int l = 0, sz = v.size(); for (int i = 1; i < sz; i++) { if (v[i] - v[l] != i - l) { if (i - l == 1) cout << v[l] << ","; else cout << v[l] << "-" << v[i - 1] << ","; l = i; } } if (l == sz - 1) cout << v[sz - 1]; else cout << v[l] << "-" << v[sz - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; const int OO = (int)2e9; const double eps = 1e-9; int daysInMonths[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int di[] = {-1, 0, 1, 0}; int dj[] = {0, 1, 0, -1}; int arr[1002], maxi = -1; void Gen(string s) { int res = 0; for (int i = (0); i < ((int)s.size()); i++) { if (s[i] != ',') { res *= 10; res += (s[i] - '0'); } else if (s[i] == ',') { arr[res]++; if (res > maxi) maxi = res; res = 0; } } arr[res]++; if (res > maxi) maxi = res; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; Gen(s); for (int i = (1); i < (1001); i++) { if (arr[i] != 0) { int last_non_zero = i, j; for (j = i;; j++) { if (arr[j] != 0) last_non_zero = j; else break; } if (i == last_non_zero) cout << last_non_zero; else cout << i << "-" << last_non_zero; if (maxi != last_non_zero) cout << ","; i = last_non_zero; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string ss; cin >> ss; int n = ss.length(); int freq[1010] = {0}; int ii = 0, jj = 0; vector<pair<int, int>> vex; for (int i = 0; i < n; i++) { string s = ""; while (ss[i] != ',' && i < n) { s += ss[i]; i++; } int l = s.size(), num = 0; for (long long j = l - 1; j >= 0; j--) { num += (s[j] - '0') * pow(10, l - 1 - j); } freq[num]++; } int j = 0; for (int i = 0; i < 1005; i++) { if (freq[i] != 0) { ii = i; for (j = i; j < 1005; j++) { if (freq[j] == 0) { jj = j - 1; break; } } vex.push_back(make_pair(ii, jj)); i = j; } } for (int i = 0; i < vex.size(); i++) { if (i == vex.size() - 1) { if (vex[i].first != vex[i].second) { cout << vex[i].first << "-" << vex[i].second; } else { cout << vex[i].first; } } else { if (vex[i].first != vex[i].second) { cout << vex[i].first << "-" << vex[i].second << ","; } else { cout << vex[i].first << ","; } } } }
#include <bits/stdc++.h> using namespace std; int main() { bool mark[1005]; memset(mark, false, sizeof(mark)); char c; int n; while (scanf("%d%c", &n, &c)) { mark[n] = true; if (c == '\n') break; } vector<pair<int, int> > ans; int start = INT_MAX, end = -1; for (int i = 0; i < 1005; i++) { if (mark[i] == false) { if (end != -1) { ans.push_back(pair<int, int>(start, end)); } start = INT_MAX; end = -1; } else { start = min(start, i); end = max(end, i); } } for (int i = 0; i < int(ans.size()); i++) { if (ans[i].first == ans[i].second) { cout << ans[i].first; } else { cout << ans[i].first << "-" << ans[i].second; } if (i < int(ans.size()) - 1) cout << ","; } cout << "" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string second; cin >> second; string s1[10001]; string s2 = ""; vector<int> v(1001, false); for (int i = 0; i < second.length(); i++) { if (second[i] == ',') { stringstream geek(s2); int x = 0; geek >> x; if (v[x] == false) v[x] = true; s2 = ""; } else s2 += second[i]; } stringstream geek(s2); int x = 0; geek >> x; if (v[x] == false) v[x] = true; int c = 0; string s3 = ""; int i; for (i = 1; i <= 1000; i++) { if (v[i] == true) c++; else { if (c > 0) { int k2 = i - 1; int k1 = i - c; stringstream ss, ss1; ss << k1; string s4; ss >> s4; ss1 << k2; string s5; ss1 >> s5; if (i - 1 == i - c) s3 += s4 + ','; else s3 += s4 + '-' + s5 + ','; } c = 0; } } if (c > 0) { int k2 = i - 1; int k1 = i - c; stringstream ss, ss1; ss << k1; string s4; ss >> s4; ss1 << k2; string s5; ss1 >> s5; if (i - 1 == i - c) s3 += s4 + ','; else s3 += s4 + '-' + s5 + ','; } cout << s3.substr(0, s3.length() - 1); }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); cout.tie(0); int n = 0, massimo = 0; string s; bool p[1003], trattino = false; for (int i = 0; i < 1003; i++) p[i] = false; cin >> s; for (int i = 0; i < s.length(); i++) if (s[i] != ',') n = 10 * n + (s[i] - '0'); else { p[n] = true; massimo = max(massimo, n); n = 0; } p[n] = true; massimo = max(massimo, n); for (int i = 1; i < 1003; i++) { if ((p[i - 1] == false) && (p[i] == true)) cout << i; else if ((p[i - 1] == true) && (p[i] == true)) trattino = true; else if ((p[i - 1] == true) && (p[i] == false)) { if (trattino == true) { trattino = false; cout << "-" << i - 1; } if (i - 1 < massimo) cout << ","; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1000; char data[N]; vector<int> pages; int main() { scanf("%s", data); int n = strlen(data); for (int i = 0; i < n; i++) { int tmp; sscanf(&data[i], "%d", &tmp); pages.push_back(tmp); while (i < n && data[i] >= '0' && data[i] <= '9') i++; } sort((pages).begin(), (pages).end()); pages.erase(unique((pages).begin(), (pages).end()), pages.end()); for (int i = 0; i < pages.size(); i++) { int val = pages[i]; int dl = 1; while (i + 1 < pages.size() && pages[i + 1] == pages[i] + 1) { dl++; i++; } if (dl == 1) printf("%d", val); else printf("%d-%d", val, pages[i]); if (i < pages.size() - 1) printf(","); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, m = 1, a = 0, i; string s, s1, s2; vector<int> v; cin >> s1; for (i = s1.size() - 1; i >= 0; i--) { if (s1[i] != ',') { a += (s1[i] - '0') * m; m *= 10; } else { v.push_back(a); m = 1; a = 0; } } v.push_back(a); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); cout << v[0]; for (i = 0; i < v.size() - 1; i++) { if (v[i + 1] - v[i] > 1) { if (n > 0) { cout << "-" << v[i]; } cout << "," << v[i + 1]; n = 0; } if (v[i + 1] - v[i] == 1) { n++; } } if (n > 0) { cout << "-" << v[i]; } return 0; }
#include <bits/stdc++.h> using namespace std; bool a[1005]; int main() { int n, x, i, j; bool flag = false; while (scanf("%d,", &n) != EOF) a[n] = true; for (i = j = 1; i < 1001; i = ++j) { if (a[i]) { j = i; while (a[j]) j++; j--; if (flag) cout << ','; else flag = true; if (i == j) cout << i; else cout << i << '-' << j; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int BIG = 1e5 + 9; const int INF = 1e9 + 9; const long long BINF = 1e18 + 9; const double SML = (1e-7); string s, num; vector<int> v; vector<vector<int> > ans; bool check[1009]; int power(int x, int n) { if (n == 0) { return 1; } int sq = power(x, n / 2); sq = sq * sq; if (n % 2 != 0) { sq = sq * x; } return sq; } int string_to_int(string& s) { int ans = 0; for (int i = s.size() - 1, j = 0; i >= 0; i--, j++) { ans = ans + (s[i] - '0') * power(10, j); } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] != ',') { num.push_back(s[i]); } else { if (!check[string_to_int(num)]) { check[string_to_int(num)] = true; v.push_back(string_to_int(num)); } num = ""; } } if (!check[string_to_int(num)]) { v.push_back(string_to_int(num)); } sort(v.begin(), v.end()); ans.push_back(vector<int>()); for (int i = 0; i < v.size(); i++) { if (ans.back().empty()) { ans.back().push_back(v[i]); } else if (v[i] == ans.back().back() + 1) { ans.back().push_back(v[i]); } else { ans.push_back(vector<int>()); ans.back().push_back(v[i]); } } for (int i = 0; i < ans.size(); i++) { if (ans[i].size() == 1) { cout << ans[i].back(); } else { cout << ans[i].front() << '-' << ans[i].back(); } if (i != ans.size() - 1) { cout << ','; } } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> split(string s) { vector<int> xs; stringstream ss(s); string item; while (getline(ss, item, ',')) { xs.push_back(stoi(item)); } return xs; } int main() { string s; getline(cin, s); vector<int> xxs = split(s); sort(xxs.begin(), xxs.end()); vector<pair<int, int>> sol; for (int i = 0; i < xxs.size(); i++) { int st = xxs[i]; int e = st; while (i < xxs.size() - 1 && (e + 1 == xxs[i + 1] || e == xxs[i + 1])) { e = xxs[i + 1]; i++; } sol.push_back(make_pair(st, e)); } for (int i = 0; i < sol.size(); i++) { if (sol[i].first != sol[i].second) { cout << sol[i].first << "-" << sol[i].second; } else { cout << sol[i].first; } if (i != sol.size() - 1) { cout << ","; } } return 0; }
#include <bits/stdc++.h> using namespace std; string s; bool b[1010]; int main() { cin >> s; int n = s.size(); int a = 0, m = 0; for (int i = 0; i < n; i++) { if (s[i] == ',') { b[a] = true; if (a > m) m = a; a = 0; } else { a *= 10; a += s[i] - '0'; } } b[a] = true; if (m < a) m = a; bool t = false; for (int i = 1; i <= m; i++) { if (!t && b[i] && !b[i + 1]) { cout << i; if (i != m) cout << ","; } if (!t && b[i] && b[i + 1]) { cout << i << "-"; t = true; } else if (t && !b[i + 1]) { cout << i; if (i != m) cout << ","; t = false; } } return 0; }
#include <bits/stdc++.h> using namespace std; set<int> s; string a; int main() { cin >> a; int z = 0; while (1) { int where = a.find(","); if (where == a.npos) { string x = a.substr(z, a.size() - z); int y = 0; for (int i = 0; i < x.size(); i++) { y = y * 10 + x[i] - '0'; } s.insert(y); break; } string x = a.substr(z, where - z); z = where + 1; int y = 0; for (int i = 0; i < x.size(); i++) { y = y * 10 + x[i] - '0'; } s.insert(y); a[where] = '.'; } int y = -233; int zz = 0; int c[1001] = {0}; for (set<int>::iterator it = s.begin(); it != s.end(); ++it) { int x = *it; if (x == y + 1) { if (c[y] < 0) { int front = 0 - c[y]; c[x] = c[y]; c[front]++; zz = front; } else { c[y]++; c[x] = 0 - y; zz = y; } } else { c[x] = 1; zz = x; } y = x; } for (int i = 1; i <= zz; i++) { if (c[i] == 1) { cout << i; if (i != zz) { cout << ','; } } if (c[i] > 1) { cout << i << '-' << i + c[i] - 1; if (i != zz) { cout << ','; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, flag, i, comma; char ch; bool visit[1001]; memset(visit, false, sizeof(bool) * 1001); vector<int> cell; while (cin >> a) { if (visit[a] == false) { visit[a] = true; cell.push_back(a); } cin >> ch; } flag = 0; comma = 0; sort(cell.begin(), cell.end()); for ((i) = (0); (i) < (int)(cell.size()); (i)++) { if (i < cell.size() - 1 && cell[i + 1] - cell[i] == 1) { if (flag == 0) { a = i; b = i + 1; flag = 1; } else { b = i + 1; } } else { if (comma == 1) cout << ","; if (flag == 1) { cout << cell[a] << "-" << cell[b]; } else { cout << cell[i]; } flag = 0; comma = 1; } } cout << endl; return 0; }
#include <bits/stdc++.h> using ul = std::uint32_t; using li = std::int32_t; using ull = std::uint64_t; using ll = std::int64_t; std::vector<ul> v; std::string s; int main() { std::getline(std::cin, s); std::stringstream ss(s); while (std::getline(ss, s, ',')) { std::stringstream ss(s); ul t; ss >> t; v.push_back(t); } std::sort(v.begin(), v.end()); bool flag = false; for (ul i = 0, j = 0; i != v.size(); i = j) { for (++j; j != v.size() && v[j - 1] + 1 >= v[j]; ++j) ; if (flag) { std::putchar(','); } flag = true; if (v[j - 1] == v[i]) { std::printf("%u", v[i]); } else { std::printf("%u-%u", v[i], v[j - 1]); } } std::putchar('\n'); return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> a; int main() { string s; cin >> s; int cur = 0, mul = 1; for (int i = s.length() - 1; i >= 0; --i) { if (s[i] == ',') { a.push_back(cur); mul = 1; cur = 0; } else { cur += mul * (s[i] - 48); mul *= 10; } } a.push_back(cur); sort(a.begin(), a.end()); int L; int last = a[0]; bool ok = 0; printf("%d", a[0]); L = a[0]; for (int i = 1; i < a.size(); ++i) { if (a[i] == last) continue; if (a[i] == last + 1) { ok = 1; last = a[i]; } else { if (ok && L != last) { printf("-%d", last); L = last; } last = a[i]; printf(",%d", a[i]); L = a[i]; } } if (ok && L != last) printf("-%d", last); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 10; char str[maxn]; long long N; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> str + 1; N = strlen(str + 1); long long pos = 1; vector<long long> v; while (pos <= N) { long long num = 0; while (pos <= N && str[pos] != ',') { num = num * 10 + str[pos] - '0'; ++pos; } ++pos; v.push_back(num); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); vector<pair<long long, long long> > stk; for (long long i = 0; i < v.size(); ++i) { if (stk.empty() || stk.back().second + 1 != v[i]) { stk.push_back({v[i], v[i]}); } else { pair<long long, long long> top = stk.back(); stk.pop_back(); stk.push_back({top.first, top.second + 1}); } } for (long long i = 0; i < stk.size(); ++i) { pair<long long, long long> now = stk[i]; if (now.first == now.second) { cout << now.first; } else { cout << now.first << "-" << now.second; } if (i == (long long)stk.size() - 1) { cout << endl; } else { cout << ","; } } return 0; }
#include <bits/stdc++.h> using namespace std; void solve(int test_number); void pre() { cout.setf(ios::fixed); cout.precision(20); cerr.setf(ios::fixed); cerr.precision(3); } void post() { fprintf(stderr, "\n"); fprintf(stderr, "Execution time: %Lf", (long double)clock()); } const int MAXN = 100100; set<int> set_; vector<int> ans; inline void solve(int test_number) { string s; cin >> s; string s1 = ""; for (int i = 0; i < ((int)(s).size()); i++) { { if (s[i] == ',') { stringstream str; int g; str << s1 << ' '; str >> g; set_.insert(g), s1 = ""; } else s1 += s[i]; } } stringstream str; int g; str << s1 << ' '; str >> g; set_.insert(g); for (auto x : set_) ans.push_back(x); sort((ans).begin(), (ans).end()); if (((int)(ans).size()) == 1) { printf("%d", ans[0]); return; } int l = 0, r = 1; while (r < ((int)(ans).size())) { if (ans[r] - ans[r - 1] > 1) { if (r - 1 != l) printf("%d-%d,", ans[l], ans[r - 1]); else printf("%d,", ans[l]); l = r; } r++; } if (l != ((int)(ans).size()) - 1) printf("%d-%d", ans[l], ans[((int)(ans).size()) - 1]); else printf("%d", ans[l]); return; } int main() { pre(); int n = 1; for (int i = 0; i < n; i++) { solve(i + 1); } post(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { string s; int sz, k, p, m, i, j, h, t, f, a[110]; cin >> s; sz = s.length(); k = 1; p = 1; m = 0; f = 0; for (i = sz - 1; i > 0; i--) if (s[i] != ',') { m += k * ((int)s[i] - 48); f = 1; k = k * 10; if (s[i - 1] == ',') { k = 1; a[p] = m; p++; m = 0; f = 0; } } if (f == 0) { a[p] = (int)s[0] - 48; p++; } else { m += k * ((int)s[0] - 48); a[p] = m; p++; } p--; for (i = 1; i < p; i++) for (j = i + 1; j <= p; j++) if (a[i] > a[j]) swap(a[i], a[j]); if (p == 1) { cout << a[p]; return 0; } h = 1; t = 1; f = 0; for (i = 2; i < p; i++) { if (a[t] != a[i]) { if (a[i] - 1 == a[t]) t = i; else { if (f != 0) { cout << ","; } if (t > h) cout << a[h] << "-" << a[t]; else cout << a[h]; f = t; h = i; t = i; } } } if (f != 0) cout << ","; if ((a[p] - a[t] == 1) && (a[h] != a[p])) cout << a[h] << "-" << a[p]; else if ((t != p - 1) && (a[h] != a[t])) cout << a[h] << "-" << a[t]; else { if (f != h) cout << a[h]; if (t > h) cout << "-" << a[t]; if (a[h] != a[p]) cout << "," << a[p]; } return EXIT_SUCCESS; }
#include <bits/stdc++.h> using namespace std; char to_low(char c) { if (c >= 'A' && c <= 'Z') return c - 'A' + 'a'; return c; } long long ToInt(string s) { long long ans = 0; for (int i = 0; i < s.length(); i++) ans = ans * 10 + (s[i] - 48); return ans; } string ToStr(long long n) { string ans; long long k = n; while (k != 0) { ans += char(k % 10 + 48); k /= 10; } reverse(ans.begin(), ans.end()); return ans; } string toRoman(string s) { long long n = ToInt(s); string digs[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"}; string tens[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "C"}; string hundreds[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", "M"}; string th[] = {"", "M", "MM", "MMM", "MMMM"}; string ans; ans += th[n / 1000]; n %= 1000; ans += hundreds[n / 100]; n %= 100; ans += tens[n / 10]; n %= 10; ans += digs[n]; return ans; } long long to10(string a, int n) { reverse(a.begin(), a.end()); long long ans = 0; long long k = 1; int c; for (int i = 0; i < a.length(); i++, k *= n) { c = (a[i] - 48); if (a[i] == 'A') c = 10; if (a[i] == 'B') c = 11; if (a[i] == 'C') c = 12; if (a[i] == 'D') c = 13; if (a[i] == 'E') c = 14; if (a[i] == 'F') c = 15; if (a[i] == 'G') c = 16; if (a[i] == 'H') c = 17; if (a[i] == 'I') c = 18; if (a[i] == 'J') c = 19; if (a[i] == 'K') c = 20; if (a[i] == 'L') c = 21; if (a[i] == 'M') c = 22; if (a[i] == 'N') c = 23; if (a[i] == 'O') c = 24; if (a[i] == 'P') c = 25; if (a[i] == 'Q') c = 26; ans += c * k; } return ans; } string toX(long long n, int sys) { string ans; long long k = n; string voc[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S"}; while (k != 0) { ans += voc[k % sys]; k /= sys; } reverse(ans.begin(), ans.end()); return ans; } int main() { int k, a[2000], mx = -1, st; char c = '.'; memset(a, 0, sizeof(a)); string s, p; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == ',') { k = atoi(p.c_str()); mx = max(mx, k); a[k] = 1; p.clear(); continue; } p += s[i]; } k = atoi(p.c_str()); mx = max(mx, k); a[k] = 1; p.clear(); int cnt = 0; bool fl = false; for (int i = 0; i <= mx + 1; i++) { if (a[i] == 0) continue; if (a[i] == a[i + 1] && !fl) { st = i; fl = true; continue; } if (a[i] != a[i + 1] && fl && (i - st + 1) >= 2) { if (cnt >= 1) cout << ","; cout << st << "-" << i; cnt++; fl = false; continue; } if (a[i] != a[i + 1] && fl && (i - st + 1) < 3) { if (cnt >= 1) cout << ","; cout << st << "," << i; cnt++; fl = false; continue; } if (a[i] != a[i + 1] && !fl) { if (cnt >= 1) cout << ","; cout << i; cnt++; continue; } } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[1010]; bool b[1010]; int main() { bool H = false; int st, en, n = 0, num = 0, x = 0; string s; cin >> s; s += ','; for (int i = 0; i < s.length(); ++i) { if (s[i] == ',') { a[n] = num; num = 0; ++n; } else { num *= 10; num += s[i] - '0'; } } for (int i = n - 1; i >= 0; --i) { b[a[i]] = true; } for (int i = 10000; i >= 0; --i) if (b[i]) x = i; st = x; for (int i = x; i < 1005; ++i) { if (b[i] == false) { en = i - 1; if (st != en) { if (H) cout << ","; cout << (st) << '-' << (en); H = true; } else { if (H) cout << ","; cout << (st); H = true; } while (b[i] == false) i++; st = i; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; while (cin >> s) { int val = 0, occ[2000] = {0}; vector<int> vec; bool flag = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == ',') vec.push_back(val), val = 0; else val = val * 10 + s[i] - '0'; } vec.push_back(val); for (int i = 0; i < vec.size(); i++) occ[vec[i]]++; for (int i = 1; i <= 1000; i++) { if (occ[i]) { int j = i; while (j + 1 <= 1000 && occ[j + 1]) { j++; } if (flag) cout << ','; if (j - i > 0) { cout << i << '-' << j; i = j; } else cout << i; flag = 1; } } } }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int inf = 1e18 + 1; bool sortbyse(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } void solve() { string s; cin >> s; long long ar[1002] = {}; long long n = s.length(), m = 0; for (long long i = 0; i < n; i++) { if (s[i] == ',') { ar[m]++; m = 0; } else m = (m * 10) + (int)(s[i] - '0'); } ar[m]++; bool x = 0; for (long long i = 1; i < 1002; i++) { if (x == 0 && ar[i] > 0) { x = 1; cout << i; } else if (ar[i + 1] == 0 && ar[i] > 0 && ar[i - 1] > 0) cout << "-" << i; else if (x == 1 && ar[i - 1] == 0 & ar[i] > 0) cout << "," << i; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int q; q = 1; while (q--) { solve(); cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int str_to_num(string str) { int num = 0; for (int i = 0; i < str.size(); i++) { num = num * 10 + (str[i] - 48); } return num; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s, ans = ""; cin >> s; vector<int> v; vector<pair<int, int> > vec; bool visited = false; for (int i = 0; i < s.size(); i++) { if (s[i] == ',') { v.push_back(str_to_num(ans)); ans = ""; continue; } ans += s[i]; } v.push_back(str_to_num(ans)); sort(v.begin(), v.end()); int start = v[0], end = v[0]; for (int i = 1; i < v.size(); i++) { if (v[i] - v[i - 1] > 1 && i != 0) { vec.push_back(make_pair(start, end)); start = v[i]; } if (i == v.size() - 1) vec.push_back(make_pair(start, v.back())); end = v[i]; } for (int i = 0; i < vec.size(); i++) { if (vec[i].first != vec[i].second) cout << vec[i].first << "-" << vec[i].second; else cout << vec[i].first; if (i != vec.size() - 1) cout << ","; } if (v.size() == 1) cout << v.back(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> fun(string s) { vector<int> a; string t; int x = 0; for (int i = 0; i < s.size(); i++) { if (s[i] != ',') { t += s[i]; } else { int size = t.size(); int u = pow(10, size - 1); for (int j = 0; j < size; j++) { x += (t[j] - '0') * u; u /= 10; } a.push_back(x); t.clear(); x = 0; } } int u = pow(10, t.size() - 1); for (int j = 0; j < t.size(); j++) { x += (t[j] - '0') * u; u /= 10; } a.push_back(x); return a; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; vector<int> ar = fun(s); vector<bool> a(1001, false); int x = 1001, y = 0; int u = 0, v = 0, c = 0; for (int i = 0; i < ar.size(); i++) { { a[ar[i]] = true; x = min(x, ar[i]); y = max(y, ar[i]); } } for (int i = x; i <= y; i++) { if (a[i] && c == 0) { u = i; c++; } else if (a[i]) { v = i; } if (!a[i] && u > 0 && v > 0) { cout << u << '-' << v << ','; c = 0; u = 0; v = 0; } else if (!a[i] && u > 0 && v == 0) { cout << u << ','; u = 0; c = 0; } } if (u > 0 && v > 0) { cout << u << '-' << v << endl; } else if (u > 0 && v == 0) { cout << u << endl; } }
#include <bits/stdc++.h> using namespace std; string toString(int v) { if (v == 0) return "0"; string res; while (v) { res += (v % 10) + '0'; v /= 10; } reverse(res.begin(), res.end()); return res; } int main() { string s; cin >> s; s.insert(0, 1, ','); int pos = 0; set<int> vals; set<int>::iterator it; int n = (int)s.size(); while (pos != n) { int curr = s.find(',', pos + 1); if (curr == -1) { curr = (int)s.size(); } int val = atoi(s.substr(pos + 1, curr - pos - 1).c_str()); vals.insert(val); pos = curr; } vals.insert(10005000); int l = *vals.begin(); vals.erase(vals.begin()); int c = l, r; vector<string> res; while (!vals.empty()) { int curr = *vals.begin(); if (curr == c + 1) { c = curr; } else { if (l != c) { res.push_back(toString(l) + "-" + toString(c)); } else res.push_back(toString(c)); l = c = curr; } vals.erase(vals.begin()); } for (int i = 0; i < res.size(); ++i) { cout << res[i]; if (i < (int)res.size() - 1) cout << ','; } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void print1d(vector<T> &a) { for (long long int i = 0; i < a.size(); i++) { cout << a[i] << " "; } cout << endl; } vector<long long int> divisor(long long int n) { vector<long long int> a; for (long long int i = 1; i * i <= n; i++) { if (n % i == 0) { if (n / i == i) a.push_back(i); else { a.push_back(i); a.push_back(n / i); } } } return a; } bool sortsecond(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b) { return a.second < b.second; } bool isPrime(long long int n) { for (long long int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } vector<string> split_string(const string &s, const string &delimiter) { vector<string> token; string ans; size_t end_point, start_point = 0, delim_length = delimiter.length(); while ((end_point = s.find(delimiter, start_point)) != string::npos) { ans = s.substr(start_point, end_point - start_point); start_point = end_point + delim_length; token.push_back(ans); } token.push_back(s.substr(start_point)); return token; } bool is_vowel(const char &a) { switch (a) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': case 'A': case 'E': case 'I': case 'O': case 'U': return true; break; default: return false; break; } } void solve() { string delimiter = ","; string s; cin >> s; vector<string> e = split_string(s, delimiter); vector<long long int> a(e.size(), 0); for (long long int i = 0; i < e.size(); i++) { a[i] = stoi(e[i]); } sort(a.begin(), a.end()); auto it = std::unique(a.begin(), a.end()); a.resize(std::distance(a.begin(), it)); long long int c = a[0], k = a[0] + 1; for (long long int i = 1; i < a.size(); i++) { if (a[i] == k) k++; else { if (c + 1 == k) cout << c << ","; else cout << c << "-" << k - 1 << ","; c = a[i]; k = a[i] + 1; } } if (c + 1 == k) cout << c << endl; else cout << c << "-" << k - 1 << endl; } int32_t main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int s[100000], n[100000], len1 = 0, len2 = 0, i, flag = 0, c = 0, start = 0; char ch; while (scanf("%d,", &s[len1++]) == 1) ; --len1; sort(s, s + len1); for (i = 0; i < len1; ++i) { if (!i) n[len2++] = s[i]; else if (s[i] != s[i - 1]) n[len2++] = s[i]; } for (i = 0; i < len2; ++i) { if (!i) cout << n[i]; else if ((n[i] - n[i - 1]) == 1) { if (i < len2 - 1) { flag = 1; continue; } else cout << "-" << n[i]; } else { if (flag) { cout << "-" << n[i - 1]; flag = 0; } cout << "," << n[i]; } } cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); set<int> v; for (int i = 0; i < n; ++i) { string num = ""; while (i < n && s[i] != ',') num += s[i], i++; int x = 0; reverse(num.begin(), num.end()); for (int j = 0; j < num.size(); ++j) { x += int(num[j] - '0') * pow(10, j); } v.insert(x); } auto it = v.begin(); while (it != v.end()) { cout << *it; int x = *it; auto it2 = it; it2++; while (*it2 - *it == 1 && it2 != v.end()) { it++; it2++; } if (*it != x) cout << '-' << *it; it++; if (it != v.end()) cout << ','; } }
#include <bits/stdc++.h> using namespace std; int Convert(string a) { int ret = 0; int i; for (i = 0; i < a.length(); i++) { ret = ret * 10 + a[i] - '0'; } return ret; } bool num(char a) { return (a <= '9' && a >= '0'); } int main() { bool pages[1024]; int i, j; int beg, end, leng; bool first = true; string work[1024], in; for (i = 0; i < 1024; i++) { pages[i] = false; work[i] = ""; } cin >> in; leng = in.length(); for (i = 0, j = 0; i < leng; i++, j++) { if (in[i] == ',') { work[j] = ","; } else { while (num(in[i])) { work[j] += in[i]; i++; } } } leng = j; for (i = 0; i < leng; i++) { if (work[i] != ",") { pages[Convert(work[i])] = true; } } for (i = 0; i < 1024; i++) { if (pages[i]) { if (!pages[i + 1]) { if (!first) cout << ","; else first = false; cout << i; } else { if (!first) cout << ","; else first = false; beg = i; end = i; while (pages[end + 1]) end++; cout << beg << "-" << end; i = end; } } } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int64_t a[1050]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; while (1) { int64_t x = s.find(','); if (x == string::npos) break; a[stoll(s.substr(0, x))] = 1; s.erase(0, x + 1); } a[stoll(s)] = 1; vector<int64_t> v; vector<string> ans; for (int64_t i = 0; i < 1050; ++i) { if (a[i]) { v.push_back(i); } else { if ((int64_t)(v).size() == 1) { ans.push_back(to_string(v.front())); } else if ((int64_t)(v).size() > 1) { ans.push_back(to_string(v.front()) + "-" + to_string(v.back())); } v.clear(); } } s.clear(); for (auto& x : ans) s += x + ','; s.erase((int64_t)(s).size() - 1, 1); cout << s; }
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ans; int x; char c; int a[1010]; int main() { cin >> x; a[x] = 1; while (cin >> c) { cin >> x; a[x] = 1; } int j = 0; while (j <= 1002) { if (a[j] == 1) if (a[j + 1] == 1) { int k = j + 1; while (a[k] == 1) k++; k--; ans.push_back(make_pair(j, k)); j = k + 1; } else ans.push_back(make_pair(j, -1)); j++; } if (ans[0].second == -1) cout << ans[0].first; else cout << ans[0].first << '-' << ans[0].second; for (int i = 1; i <= int(ans.size()) - 1; i++) if (ans[i].second == -1) cout << ',' << ans[i].first; else cout << ',' << ans[i].first << '-' << ans[i].second; return 0; }
#include <bits/stdc++.h> using namespace std; int toInt(const string &s) { int d = 0; int i = 0; while (i < s.length()) { d = d * 10 + (s[i] - '0'); i++; } return d; } string toString(const int a) { string tm = ""; int dm = a; while (dm) { tm += (dm % 10 + '0'); dm /= 10; } reverse(tm.begin(), tm.end()); return tm; } int main(int argc, char **argv) { string s; cin >> s; map<int, int> mp; for (int i = 0; i < s.length(); i++) { string tmp = ""; while (s[i] != ',' && (i < s.length())) { tmp += s[i]; i++; } mp[toInt(tmp)]++; } string ans = ""; for (int i = 1; i <= 1000; i++) { if (mp[i]) { int d = i; while (mp[i]) i++; if (i - 1 != d) ans += toString(d) + '-' + toString(i - 1) + ','; else ans += toString(d) + ','; } } for (int i = 0; i < ans.length() - 1; i++) cout << ans[i]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, l, m, n, strt, f = 0, no; string s, sd; vector<long long int> v; map<long long int, long long int> mp; cin >> s; n = s.length(); for (i = 0; i < n; i++) { if (s[i] != ',') { sd = sd + s[i]; } else { no = stoi(sd); if (mp[no] == 0) { mp[no]++; v.push_back(no); } sd.clear(); } } no = stoi(sd); if (mp[no] == 0) { v.push_back(no); } sort(v.begin(), v.end()); for (i = 0; i < v.size(); i++) { if (i + 1 < v.size() && v[i] + 1 == v[i + 1]) { if (f == 0) { strt = v[i]; f = 1; } } else { if (f == 1 && i != v.size() - 1) cout << strt << "-" << v[i] << ","; if (f == 1 && i == v.size() - 1) cout << strt << "-" << v[i]; if (f == 0 && i != v.size() - 1) cout << v[i] << ","; if (f == 0 && i == v.size() - 1) cout << v[i]; f = 0; } } }
#include <bits/stdc++.h> using namespace std; int table[1111]; int main() { int n = 0; while (scanf("%d,", &table[n]) == 1) n++; sort(table, table + n); int i = 0, l, r; while (i < n) { l = table[i]; i++; while (i < n && (table[i] == table[i - 1] || table[i] == table[i - 1] + 1)) i++; if (table[i - 1] != l) printf("%d-%d", l, table[i - 1]); else printf("%d", l); if (i < n) printf(","); } }
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) { ans = (ans * a); } a = (a * a); b >>= 1; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; int n = s.size(), i; vector<int> v; map<int, int> m; int j = 1; for (i = 0; i < n; i++) { int no = 0; while (i < n && s[i] != ',') { int k = s[i] - '0'; no = no * 10 + k; i++; } if (m[no] == 0) v.push_back(no); m[no] = j; j++; } string ans = ""; for (i = 1; i < 1001; i++) { set<int> pos; int k = i; while (m[i]) { pos.insert(m[j]); i++; } if (pos.size() > 0) { auto it = pos.begin(); int pre = (*it); for (it++; it != pos.end(); it++) { if ((*it) - pre == 1) { pre = (*it); } else break; } if (it == pos.end()) { if (k != (i - 1)) ans += to_string(k) + "-" + to_string(i - 1) + ","; else { ans += to_string(k) + ","; } i--; } else { ans += to_string(k) + ","; i = k; } } } cout << ans.substr(0, ans.size() - 1); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; for (int i = 0; i < str.size(); ++i) if (str[i] == ',') str[i] = ' '; stringstream ss(str); int temp; set<int> nums; while (ss >> temp) nums.insert(temp); vector<int> v; for (typeof(nums.begin()) it = nums.begin(); it != nums.end(); ++it) v.push_back(*it); int i = 0, j = 0; stringstream ss1; while (i < v.size()) { while (j + 1 < v.size() && v[j + 1] - v[j] == 1) j++; ss1 << ","; if (i == j) ss1 << v[i]; else ss1 << v[i] << "-" << v[j]; i = j = j + 1; } string ans; ss1 >> ans; ans = ans.substr(1, ans.size() - 1); cout << ans << endl; return 0; }