CodeForces - 977A:Wrong Subtraction(水题)

39 篇文章 1 订阅

链接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拿一血的真的没法细品,这也太。。。。。。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值