CF1702A Round Down the Price 题解
题意:给定一个数 \(n\),找出一个数为 \(10^k \leq n\),求二者的差。
建立一个数组,储存 \(10^k\),每次直接查询求差输出。
注意数据范围。
#include<cstdio>
#include<iostream>
using namespace std;
long long s[15]={0,1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000};
int t,m;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&m);
for(int i=1;i<=11;i++){
if(m<s[i]){
printf("%d\n",m-s[i-1]);
break;
}
}
}
return 0;
}

浙公网安备 33010602011771号