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次操作,然后每次操作把所有数减 ...
随机推荐
- Ros学习——launch文件解析
launch文件的重点是:节点(node)元素的集合. roslaunch 则是让所有的节点共享同一个终端. 1.标签(元素)说明 1. group标签 2. node标签 <group ns= ...
- 解决swfupload改变display属性后flash重新加载的问题(chome,safari内核的所有浏览器)
最近在做的项目中有要用到上传控件,所有就用到了swfupload flash上传控件 因为在项目中要使用到Tab控件,tab控件通过改变display属性来控制tab页的显 示与隐藏.当swfuplo ...
- HDOJ 4802 GPA
Problem Description In college, a student may take several courses. for each course i, he earns a ce ...
- Struts2返回JSON数据的具体应用范例
早在我刚学Struts2之初的时候,就想写一篇文章来阐述Struts2如何返回JSON数据的原理和具体应用了,但苦于一直忙于工作难以抽身,渐渐的也淡忘了此事.直到前两天有同事在工作中遇到这个问题,来找 ...
- Spring第四篇
在spring第三篇中介绍了bean元素属性 在第四篇中介绍spring注入的方式 1 set方法注入 建立一个User类 创建私有的属性 set get 方法 重写toString方法 代码如下 ...
- java全栈day01-03注释、关键字与标识符
通常我们需要在源代码中添加文字用来对进行代码解释说明,但这些文字并不是Java代码的语法,会导致编译出错.这时我们可以使用注释来完成这一事项! 在编译时,编译器会忽略注释的存在,就好像注释内容不存在一 ...
- 有三个线程,a、b、c,a打印“T1”,b打印“T2”,c打印“T3”,a执行完后,b执行;b执行完后,c执行。如此循环100遍
有三个线程,a.b.c,a打印“T1”,b打印“T2”,c打印“T3”,a执行完后,b执行:b执行完后,c执行.如此循环100遍. package com.company; /** * 测试三个线程协 ...
- excel导出工具
介绍 excel导出工具 整个项目的代码结构如下 com \---utils +---demo # 案例相关 | | ExcelExportApplication.java # springboot启 ...
- 使用KubeAdm部署Kubernetes集群——如何访问google代码仓库及Yum源
一.申请国外服务器,部署ShadowSock服务 1.下载并创建配置文件 wget https://github.com/shadowsocks/shadowsocks-go/releases/dow ...
- hadoop下HDFS基本命令使用
前提:启动hadoop 1. 查看hdfs下 " / " 的目录 hdfs dfs -ls / 2. 创建文件夹(在 " / " 创建hadoop文件夹) hd ...