Competition/codeforces
Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2) A. Phone Numbers
shyram
2019. 4. 3. 00:54
A. Phone Numbers
https://codeforces.com/problemset/problem/1060/A
8과 나머지 숫자를 따로 세어준다.
while문을 도는데, 8에서 하나 빼고, 나머지 숫자들에서 10개를 뺀다.
만약 나머지 숫자가 10개가 안되면 8에서 부족한 만큼 뺀다.
더이상 뺄 숫자가 없으면 종료.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <bits/stdc++.h> using namespace std; int n, a, b; string s; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> s; for (int i = 0; i < s.length(); i++) { if (s[i] - '0' == 8) b++; else a++; } int ans = 0; while (a+b > 10 && b > 0) { b--; a -= 10; if (a < 0) { b += a; a = 0; } if (b < 0) break; ans++; } cout << ans; return 0; } | cs |