A. Wrong Subtraction
1 second
256 megabytes
standard input
standard output
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 nn. Tanya will subtract one from it kk times. Your task is to print the result after all kk subtractions.
It is guaranteed that the result will be positive integer number.
The first line of the input contains two integer numbers nn and kk (2≤n≤1092≤n≤109, 1≤k≤501≤k≤50) — the number from which Tanya will subtract and the number of subtractions correspondingly.
Print one integer number — the result of the decreasing nn by one kk times.
It is guaranteed that the result will be positive integer number.
512 4
50
1000000000 9
1
The first example corresponds to the following sequence: 512→511→510→51→50512→511→510→51→50.
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int k;
char a[];
while(cin>>a>>k)
{
int len=strlen(a);
int j=;
for(int i=;i<k;i++)
{
if(a[len--j]=='')
{
a[len--j]='*';
j++;
}
else
a[len--j]=a[len--j]-;
} for(int i=;i<len;i++)
{
if(a[i]!='*')
cout<<a[i];
}
cout<<endl; }
return ;
}
A. Wrong Subtraction的更多相关文章
- PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...
- [leetcode-592-Fraction Addition and Subtraction]
Given a string representing an expression of fraction addition and subtraction, you need to return t ...
- [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 ...
- PAT 1050 String Subtraction
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- [OpenCV] Samples 15: Background Subtraction and Gaussian mixture models
不错的草稿.但进一步处理是必然的,也是难点所在. Extended: 固定摄像头,采用Gaussian mixture models对背景建模. OpenCV 中实现了两个版本的高斯混合背景/前景分割 ...
- 1050 String Subtraction (20 分)
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be the ...
- 为什么委托的减法(- 或 -=)可能出现非预期的结果?(Delegate Subtraction Has Unpredictable Result)
当我们为一个委托写 -= 的时候,ReSharper 会提示“Delegate Subtraction Has Unpredictable Result”,即“委托的减法可能出现非预期的结果”.然而在 ...
- Codeforces Round #525 (Div. 2)B. Ehab and subtraction
B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减 ...
随机推荐
- python爬虫框架(1)--框架概述
框架概述 其中比较好用的是 Scrapy 和PySpider.pyspider上手更简单,操作更加简便,因为它增加了 WEB 界面,写爬虫迅速,集成了phantomjs,可以用来抓取js渲染的页面.S ...
- WPA密码攻击宝典
原则:密码以8-10位为主.11位仅限于当地手机号.一般人的多年用数字做密码的习惯和心理,先数 字.再字母,或数字.字母重复几遍,字符几乎全用小写,所以淘汰大写及"~!@#$%^&* ...
- ssh整合思想
整合过程:
- C++——const
参考:https://www.cnblogs.com/Forever-Kenlen-Ja/p/3776991.html ; //修饰变量,a不能该内容(更改为其他的值) int* const p = ...
- CF 671D Roads in Yusland
弄完之后点进去一看,竟然是div1的D题……最近真是天天被题虐哭 推荐这一篇博客 https://www.cnblogs.com/Sakits/p/8085598.html 感觉讲清楚了,也是基本照着 ...
- java 中一个char包含几个字节
背景 char包含几个字节可能记得在上学的时候书上写的是2个字节,一直没有深究,今天我们来探究一下到底一个char多少个字节? Char char在设计之初的时候被用来存储字符,可是世界上有那 ...
- delphi xe6 让 ListView 在 Android 可回弹[根据龟山阿卍原创修改为xe6版本]
Delphi XE6 找出 FMX.Platform.Android.pas 档案,并复制到自己的 Project 路径里,找到 GetScrollingBehaviour 函数,修改成如下: uni ...
- JetBrains Rider 在 Mac 环境下将 cs 文件生成 exe
因为自己的开发环境是 Mac + Rider 组合,想测试网络编程相关内容.想在Windows 虚拟机上运行一套代码来与Mac 机进行测试,但又不想在虚拟机上安装一套开发环境.最终找到的解决方案是通过 ...
- 网易云易盾中标浙报反作弊服务 助力浙江新闻App健康发展
欢迎访问网易云社区,了解更多网易技术产品运营经验. 近日,国内领先的智能业务安全平台网易云易盾和浙报传媒旗下"浙江新闻"达成合作,易盾将为浙江新闻客户端提供大数据反作弊服务,助力浙 ...
- JetBrains WebStorm 如何从GitHub上克隆的代码
工作中经常会遇到要从GitHub上拉代码,详细操作记录如下: 绑定账号 1.File->Settings->Version Control->Github 成功后会出现下面的这个账户 ...