『题解』Codeforces 1702A Round Down the Price

题意

这道题其实就是让你求出当前数字与 \(10\) 的整数幂次的差值(注意不能向上取,只能向下取)。

而且题目也标注了 \(1 \le k \le 9\),所以我们可以让 \(i\)\(0 \sim 9\) 循环一遍,如果 \(10^i \le n < 10^{i +1}\),我们就输出 \(n - 10^i\)\(n\) 代表当前数字)就行了!

直接上代码!

代码

// Problem: A. Round Down the Price
// Contest: Codeforces Round #805 (Div. 3)
// URL: https://codeforces.com/contest/1702/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

// Author: CrazyWolf

#include <bits/stdc++.h>
#define int long long
using namespace std;

void Work()
{
	int n;
	cin >> n;
	for (int i = 0; i < 10; i ++)
	{
		if (pow(10, i) <= n && n < pow(10, i + 1))
		{
			cout << (long long)(n - pow(10, i)) << endl; //注意这里一定要强制类型转换 
			return ;
		}
	}
}

signed main()
{
	int t;
	cin >> t;
	while (t --)
	{
		Work();
	}
	return 0;
}
posted @ 2022-11-26 21:39  Clyfort  阅读(64)  评论(0编辑  收藏  举报