链接:https://vjudge.net/problem/CodeForces-977A
题目
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.
题意
给出两个数字n、k,你可以对数字n操作k次。
每次操作分为两种:
- 如果n的最后一位数不为0,n-1;
- 如果n的最后一位数为0,去掉这个0.(比如“10”就会变成“1”)
输出结果。
思路
没什么好说的,分情况操作就ok。
伊丽莎白!
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n,k;
cin>>n>>k;
while(k--)
{
int m=n%10;
if(m)
n--;
else
n/=10;
}
cout<<n<<endl;
}
今天是个好日子~
学长学姐太给力了,希望我也可以┭┮﹏┭┮
当然,那个6s拿一血的真的没法细品,这也太。。。。。。