贪心_4
来源:互联网 发布:全球数据交换中心 编辑:程序博客网 时间:2024/05/17 23:03
Description
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
Input
The first line contains a single integer n (1 ≤ n ≤ 106).
Output
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
Sample Input
9
91 1 1 1 1 1 1 1 1
32
310 11 11
1.最高位数就是n
2.利用string里某个值可作为int计算,==时用引号
3.flag可以作为起始标志
4.循环结构要清晰
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<string>using namespace std;int main(){ string a; while(cin>>a) { // return 0; int len=0; for(int i=0;i<a.size();i++) len=max(len,a[i]-'0'); cout<<len<<endl; // return 0; for(int j=0;j<len;j++) { int flag=0; for(int k=0;k<a.size();k++) { if(!flag) { if(a[k]=='0') continue; else { printf("1"); a[k]--; flag=1; } } else { if(a[k]=='0') printf("0"); else { printf("1"); a[k]--; } } } printf(" "); } printf("\n"); } return 0;}
- 贪心_4
- 4_4
- 2_4
- 3_4
- 13_4
- 工作总结_4
- 集合_4
- 练习题_4
- hibernate基础_4
- Excercise 9_4
- SEH示例2_4
- 日语小说连载_4
- TaskScheduler的分析_4
- Java流_4总结
- WF4.0_4
- java 代码片段_4
- libevent简单应用_4
- 16_4(1)指来指去
- Bootstrap使用Tab和dropdown实现导航下拉菜单效果
- ansj源码浅析1
- HDU 1242 Rescue
- 【计算机组成原理】存储器
- Android中Dex分包实践
- 贪心_4
- CXF发布中java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log问题
- Linux中TCP黏包问题及其解决方案
- vs2015编译CEF
- web前端多重筛选、json
- HDOJ 1848 Fibonacci again and again
- 合并 XML 文件
- Linux使用Atomicorp的YUM源时提示key ID 4520afa9: NOKEY
- ZZULIOJ /郑轻oj 1905: 小火山的跳子游戏(GCD,思维)