Custom Subtraction
A young girl named Emily is learning how to subtract one from a number, but she has a unique way of doing it when the number has two or more digits.
Emily follows these steps:
- If the last digit of the number is not zero, she simply subtracts one from the number.
- If the last digit of the number is zero, she divides the number by 10 (effectively removing the last digit).
You are given an integer number n. Emily will perform this subtraction process k times. Your task is to determine the final result after all k subtractions. It is guaranteed that the result will always be a positive integer.
Example 1
Input:
n = 512, k = 4
Output:
50
Explanation:
512→511→510→51→50
main.cpp
C++
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal