The number on the board

Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It’s known that the length of the number didn’t change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 ≤ k ≤ 109).
The second line contains integer n (1 ≤ n < 10100000).
There are no leading zeros in n. It’s guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.

一道水题,每位数字最大到9,如果总和比k小的话,我们就把差最大的改为9。

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
const int Max=1e5+10;

char str[Max];
int cha[Max];


int cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int k;
    scanf("%d",&k);
    getchar();
    gets(str);
    int sum_digit=0;
    int len=strlen(str);

    for(int i=0;i<len;i++)
    {
        cha[i]=9-str[i]+'0';
        sum_digit += str[i]-'0';//计算总和
    }


    if(sum_digit>=k)
        printf("0\n");
    else
    {
        int sum=0;
        sort(cha,cha+len,cmp);
        for(int i=0;i<len;i++)
        {
            sum += cha[i];
            if(sum+sum_digit>=k)
            {
                printf("%d\n",i+1);
                break;
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Given the grid below for the game of ACSL Patolli, utilize the following rules to play the game. All rules must be applied in the sequential order listed. 1 . There are 2 players. Each player has 3 markers. 2. The markers move according to the roll of a die (1 – 6). 3. Markers move in numerical order around the grid. 4. If, on a die roll, a marker lands on an occupied location, then that marker loses its turn and remains at its previous location. 5. A marker can jump over another marker on its way to finish its move. 6. A marker finishes its way around the grid when it lands on location 52. It is then removed from the board. A move can’t take a marker beyond location 52. If it does, the marker remains at its previous location. 7. If, on a die roll, a marker lands on an unoccupied location that is a prime number, the marker then moves six locations forward. However, it stops immediately before any occupied location. 8. If, on a die roll, a marker lands on an unoccupied location that is a perfect square greater than 4, the marker then moves 6 locations backwards. However, it stops immediately before any occupied location. 9. If, on a die roll, a marker lands on an unoccupied location that is neither a prime number nor a perfect square, then determine if the marker made at least one horizontal move followed by at least one vertical move (such as going from 6 to 8, 11 to 13, 26 to 28 … but not 2 to 4 or 30 to 32). In that case, the marker can only land on a location on its path that is a multiple of the die roll value even if it moves a smaller distance than the die roll value. However, if all the locations in its path that are multiples are occupied, then the marker does not move from its current location. The rules listed in #7 and #8 do not apply when using #9.
最新发布
03-02

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值