G - Wrong Subtraction
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 (2≤n≤10^9, 1≤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: 512→511→510→51→50512→511→510→51→50.
解题思路:题目的意思就是给一个数n和要求执行k次操作:如果尾数是0,那么n/=10;否则就n-=1;简单模拟即可!
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
for(int i=;i<=k;++i){
if(n%)n-=;
else n/=;
}
cout<<n<<endl;
return ;
}
G - Wrong Subtraction的更多相关文章
- 详解 Python 的二元算术运算,为什么说减法只是语法糖?
原题 | Unravelling binary arithmetic operations in Python 作者 | Brett Cannon 译者 | 豌豆花下猫("Python猫&q ...
- 开源软硬一体OpenCV AI Kit(OAK)
开源软硬一体OpenCV AI Kit(OAK) OpenCV 涵盖图像处理和计算机视觉方面的很多通用算法,是非常有力的研究工具之一,且稳居开发者最喜爱的 AI 工具/框架榜首. 1.会不会被USA禁 ...
- Storyboards Tutorial 03
这一节主要介绍segues,static table view cells 和 Add Player screen 以及 a game picker screen. Introducing Segue ...
- 文件图标SVG
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink ...
- April Fools Contest 2017 题解&源码(A,数学 B,数学 C,数学 D,字符串 E,数字逻辑 F,排序,卡时间,G,数学)
A. Numbers Joke time limit per test:2 seconds memory limit per test:64 megabytes input:standard inpu ...
- [LeetCode] Fraction Addition and Subtraction 分数加减法
Given a string representing an expression of fraction addition and subtraction, you need to return t ...
- 【CF932E】Perpetual Subtraction(NTT,线性代数)
[CF932E]Perpetual Subtraction(NTT,线性代数) 题面 洛谷 CF 题解 设\(f_{i,j}\)表示\(i\)轮之后这个数恰好为\(j\)的概率. 得到转移:\(\di ...
- [Swift]LeetCode592. 分数加减运算 | Fraction Addition and Subtraction
Given a string representing an expression of fraction addition and subtraction, you need to return t ...
- [OpenCV] Samples 15: Background Subtraction and Gaussian mixture models
不错的草稿.但进一步处理是必然的,也是难点所在. Extended: 固定摄像头,采用Gaussian mixture models对背景建模. OpenCV 中实现了两个版本的高斯混合背景/前景分割 ...
随机推荐
- .htaccess使用
RewriteEngine on #请求替换 #test-zhangsan-20 替换为 test.php?name=zhangsan&age=20 RewriteRule test-([a- ...
- PAT_A1133#Splitting A Linked List
Source: PAT A1133 Splitting A Linked List (25 分) Description: Given a singly linked list, you are su ...
- 原始js表单文本框初始化获取焦点和选中
发现: 1 使用dom对象.focus() 放在 window.onload 时可以 让这个DOM对象获取焦点. 2 使用DOM对象.select() 可以选中文本框中的文字. 3 不要加上on , ...
- 00.不规则json序列化使用eval、demjson
有下面一段字符串 import json str0 = '[{"name":"白云大道营业厅","siteaddr":"x...& ...
- 熟悉RHEL7登录界面使用
Linux操作系统提供了图像界面和字符界面两种操作环境. 图像界面: 1.开启RHEL7后进入到该界面,图中用户是我们创建的本地用户,如果我们要以管理员身份登录则点击Not listed(未列出). ...
- 42.global bucket的使用:单个品牌与所有品牌销量对比
主要知识点: _global bucket的使用 本例以搜索单个品牌和所有品牌的销量对比进行学习_global .es在进行aggregation操作时都只只是在一个scope中进行聚合等操作 ...
- php 导出Excel 不用安装插件、开启配置
function export_csv($filename, $data) { header("Content-type:text/csv"); header("Cont ...
- django的时间问题
三个时间datetime.datetime.now().datetime.datetime.utcnow()与django.util.timezone.now()的区别 datetime.dateti ...
- hdu 5174 Ferries Wheel
摩天轮是一个环,周围围绕着一些缆车.每个缆车按顺序编号为1,2,3...K-1,K1,2,3...K−1,K而且每个缆车也拥有一个唯一的值且保证A[i-1] < A[i] < A[i+1] ...
- 《ABCD组》第八次作业:ALPHA冲刺
<ABCD组>第八次作业:ALPHA冲刺 项目 内容 这个作业属于哪个课程 http://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://ww ...