Codeforces Round #640 (Div. 4) 参与排名人数9749,终于弄明白账号前*的意义,*out of competition,也即虽然该用户参加本场比赛,但不参与排名。
[codeforces 1352A] Sum of Round Numbers 十进制转换
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址http://codeforces.com/contest/1352/problem/A
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
A - Sum of Round Numbers | GNU C++17 | Accepted | 15 ms | 3600 KB |
结合样例,看懂了题。
样例数据生成如下
9876
4
800 70 6 9000
9876=6+70+800+9000
基本思路,将上述9876各个位置的数取出,6,7,8,9,同时别忘了,还要还原出具体位置,6(6),7(70),8(800),9(9000).
具体详见代码
#include <stdio.h>
int a[10];
int main(){
int t,n,pos,i,tot,pow;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
pos=0,tot=0,pow=1;
while(n){
a[pos]=n%10;//取出不同位置上的值,9876,a[0]=6,a[1]=7,a[2]=8,a[3]=9
pos++,n/=10;
}
for(i=0;i<pos;i++)
if(a[i])tot++;//统计非0值
printf("%d\n",tot);
for(i=0;i<pos;i++){
if(a[i])printf("%d ",a[i]*pow);
pow*=10;//pow确定十进制数的位置,9876,6(pow=1),7(pow=10),8(pow=100),9(pow=1000)
}
printf("\n");
}
return 0;
}