码迷,mamicode.com
首页 > 其他好文 > 详细

[ CF Contest ] Sum of Round Numbers 题解

时间:2020-05-13 23:05:21      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:数组   numbers   五个   test   ace   sum   include   i++   names   

暴力 if 分解。

对于这道题的数据范围\((1≤n≤10^5 )\),可以对每个测试用五个 if 来解决分解问题,用数组存储答案然后输出。

#include <iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	for(int i=1;i<=t;i++){
		int n,a[4]={0},c=0,d=0;
		cin>>n;
		if(n>1000){
			a[0]=n-(n%1000);
			n%=1000;
			c++;
		}if(n>100){
			a[1]=n-(n%100);
			n%=100;
			c++;
		}if(n>10){
			a[2]=n-(n%10);
			n%=10;
			c++;
		}if(n>=1){
			a[3]=n;
			c++;
		}
		cout<<c<<endl;
		while(d!=4){
			if(a[d]!=0)
			cout<<a[d]<<‘ ‘;
			d++;
		} 
	}
}

[ CF Contest ] Sum of Round Numbers 题解

标签:数组   numbers   五个   test   ace   sum   include   i++   names   

原文地址:https://www.cnblogs.com/Inversentropir-36/p/12885475.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!