zoukankan      html  css  js  c++  java
  • G

    Problem description

    Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:

    • if the last digit of the number is non-zero, she decreases the number by one;
    • if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).

    You are given an integer number n. Tanya will subtract one from it k times. Your task is to print the result after all k subtractions.

    It is guaranteed that the result will be positive integer number.

    Input

    The first line of the input contains two integer numbers n and k (2n10^91≤k≤50) — the number from which Tanya will subtract and the number of subtractions correspondingly.

    Output

    Print one integer number — the result of the decreasing n by one k times.

    It is guaranteed that the result will be positive integer number.

    Examples

    Input

    512 4

    Output

    50

    Input

    1000000000 9

    Output

    1

    Note

    The first example corresponds to the following sequence: 5125115105150512→511→510→51→50.

    解题思路:题目的意思就是给一个数n和要求执行k次操作:如果尾数是0,那么n/=10;否则就n-=1;简单模拟即可!

    AC代码:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int main()
     4 {
     5     int n,k;
     6     cin>>n>>k;
     7     for(int i=1;i<=k;++i){
     8         if(n%10)n-=1;
     9         else n/=10;
    10     }
    11     cout<<n<<endl;
    12     return 0;
    13 }
  • 相关阅读:
    文件操作
    字典的相关函数
    列表相关操作/列表的相关函数
    字符串相关操作/字符串相关函数
    局部变量 与 全局变量
    函数名的使用
    函数的返回值 return
    命名关键字
    收集参数
    默认形参 与 关键字实参的区别
  • 原文地址:https://www.cnblogs.com/acgoto/p/9104924.html
Copyright © 2011-2022 走看看