Codeforces Round #479 (Div. 3) A. Wrong Subtraction

时间:2023-03-09 17:54:45
Codeforces Round #479 (Div. 3)  A. Wrong Subtraction

题目网址:http://codeforces.com/contest/977/problem/A

Codeforces Round #479 (Div. 3)  A. Wrong Subtraction

Codeforces Round #479 (Div. 3)  A. Wrong Subtraction

题解:给你一个数n,进行k次变换,从末尾开始-1,512变成511,511变成510,510会把0消掉。(看Note应该都能看懂的吧~)

方法:水题。。。把数字用字符串读入,遇到末尾为0的情况就把字符串长度-1,不然就-1。然后len<=0的情况就输出0(不知道为什么不用<0就可以过了,可能不会出现这样的情况?),反之按长度一个个输出即可~

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
int main()
{
char n[];
int k;
cin >> n >> k;
int len = strlen(n);
while (k--)
{
if (n[len - ] == '')
{
len--;
}
else
{
n[len - ] -= ;
}
}
if (len == )
printf("0\n");
else
{
for (int i = ; i < len; i++)
{
printf("%c", n[i]);
}
printf("\n");
} return ;
}