[codeforces 1352A] Sum of Round Numbers 十进制转换

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

ProblemLangVerdictTimeMemory
A - Sum of Round Numbers GNU C++17Accepted15 ms3600 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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值