[codeforces 1296B] Food Buying 找规律
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址https://codeforces.com/contest/1296/problem/B
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
B - Food Buying | GNU C++11 | Accepted | 31 ms | 0 KB |
/*
9876
10973
计算过程如下
9876/10*10=9870,9876/10+9876%10=993;
993/10*10=990,993/10+993%10=102;
102/10*10=100,102/10+102%10=12;
12/10*10=10,12/10+12%10=3;
3/10*10=0,3/10+3%10=3;结束
9870+990+100+10+3=10973;
*/
//编码完成后,要测s=10^9,看int是否溢出。
/*
测了,发现已存于样例中
1
1000000000
1111111111
*/
#include <stdio.h>
int main(){
int t,n,sum;
scanf("%d",&t);
while(t--){
scanf("%d",&n),sum=0;
while(n>=10){
sum+=n/10*10;
n=n/10+n%10;
}
sum+=n;
printf("%d\n",sum);
}
return 0;
}