A
It's a easy problem. At first you must find out the number of the '8', because all of the phone numbers are began with a '8', so the number of '8' is the max of the phone numbers. Then one of the number contains about 11 different numbers. So the answer is:
min(int(number of '8'), n / 11);
my codes:
#pragma G++ optimize (2)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#define INF 0x3f3f3f3f
#define NO 30005
#define MO 100005
typedef long long ll;
//by Oliver
using namespace std;
ll read()
{
char ch = ' ', last;
ll ans = 0;
while (ch < '0' || ch > '9')
last = ch, ch = getchar();
while (ch >= '0' && ch <= '9')
ans = ans * 10 + int(ch - '0'), ch = getchar();
if (last == '-')
return -ans;
return ans;
}
void write(ll x)
{
if (x >= 10)
write(x / 10);
putchar(x % 10 + '0');
}
//head
int n, a[NO], cnt;
//variable
void init()
{
n = read();
for (int i = 1; i <= n; i++)
{
char x;
cin >> x;
a[i] = x - '0';
cnt += (a[i] == 8);
}
}
//functions
int main()
{
init();
cout << min(cnt, n / 11) << endl;
return 0;
}
//main
B
If you want to get the most sum of the all digit, you must make the most amount of '9'. So the first number can have the most number of '9'. For example: 100 => 99, 12312 => 9999. Then we just have to get the digit-sum of the rest. The sum of then is the answer. But what if the number is 999? No problem, it can just divided to 998 and 1, it's the same answer as 999 and 0.
my codes:
#pragma G++ optimize (2)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#define INF 0x3f3f3f3f
#define NO 30005
#define MO 100005
typedef long long ll;
//by Oliver
using namespace std;
ll read()
{
char ch = ' ', last;
ll ans = 0;
while (ch < '0' || ch > '9')
last = ch, ch = getchar();
while (ch >= '0' && ch <= '9')
ans = ans * 10 + int(ch - '0'), ch = getchar();
if (last == '-')
return -ans;
return ans;
}
void write(ll x)
{
if (x >= 10)
write(x / 10);
putchar(x % 10 + '0');
}
//head
ll n, ans, cnt, tot;
//variable
void init()
{
n = read();
}
//functions
int main()
{
init();
cnt = 9;
while (cnt < n)
cnt *= 10, cnt += 9, tot++;
cnt -= 9, cnt /= 10;
ans += 9 * tot;
n -= cnt;
while (n)
{
ans += n % 10;
n /= 10;
}
cout << ans << endl;
return 0;
}
//main