CodeForces 538B
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
9
1 1 1 1 1 1 1 1 1
32
3
10 11 11
解题思路:题目大意:将一个数拆分成几个由1和0组成的数。输出数的个数以及各个拆分后的数。
当n小于9的时候,只能拆分成n个1;
当n大于9时,用一个数组将n的各个位数存起来,其中最大的那个数Max则为输出数的个数;
输出时,共有Max个循环对数组输出,当数组元素大于等于1时,输出1,同时元素值减一;当数组元素等于0时,输出0;
注意:当数组输出的第一个数为0时选择不输出。直到第一个数不为0时输出。
#include<iostream>
#include<stdio.h>
#include<cstring> using namespace std;
int c[];
int main()
{
string s;
cin>>s;
int sum; if(s.length()==){
printf("%d\n",s[]-'');
for(int i=;i<=s[]-'';i++)
{
if(i==) printf("");
else
printf("");
}
printf("\n");
} else
{
int k=s.length();
for(int i=;i<=s.length();i++)
c[i]=s[s.length()-i]-'';
int Max=;
for(int i=;i<=k;i++)
{
if(c[i]>Max) Max=c[i];
}
printf("%d\n",Max);
while(Max--)
{
int i;int j=;
for(i=k;i>=;i--)
{
//cout<<i<<"H"<<c[i]<<endl;
if(c[i]==&&j==) {continue;}
else
{
j++;
if(c[i]!=){printf("");c[i]=c[i]-;}
else printf("");
}
}
printf(" ");
}
printf("\n"); }
return ;
}
CodeForces 538B的更多相关文章
- Codeforces Round #300(Div. 2)-538A.str.substr 538B.不会 538C.不会 。。。
A. Cutting Banner time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- java.io.File中的pathSeparator与separator的区别
先总的说一下区别:File.pathSeparator指的是分隔连续多个路径字符串的分隔符,例如:java -cp test.jar;abc.jar HelloWorld就是指“;” Fi ...
- 对PostgreSQL cmin和cmax的理解
看例子: 开两个终端来对比: 在终端A: [pgsql@localhost bin]$ ./psql psql () Type "help" for help. pgsql=# b ...
- [GIF] Parenting in GIF Loop Coder
In this lesson, we look at how you can build up complex animations by assigning one shape as the par ...
- [AngularJS] Catching errors with $exceptionHandler
The AngularJS $exceptionHandler service allows you to catch and handle unanticipated JavaScript erro ...
- zendserver 安装 ZendDebugger
网上都找不到支持PHP5.3及以上的Zend Debugger,然后下载了ZendStudio 10.1,发现它内置的PHP 5.3 和 5.4都支持Debugger, 这Debugger就是Zend ...
- careercup-C和C++ 13.7
13.7 写一个函数,其中一个参数是指向Node结构的指针,返回传入数据结构的一份完全拷贝. Node结构包含两个指针,指向另外两个Node. C++实现代码: typedef map<Node ...
- 一个.Net程序员:既然选择了编程,只管风雨兼程(转)
一个.Net程序员:既然选择了编程,只管风雨兼程 一次会议记录是不会有人感兴趣的,做标题党也是不道德的.所以,走了个折衷的路线,标题不叫会议记录, 内容不纯总结,技术加吐槽,经验加总结. 对于一个程序 ...
- REM 注释
REM 是DOS批处理和VB的注释语句.所谓注释语句,就是程序的执行时会跳过该行(不管它后面写的什么),它为编程者起到一个批注的功能,以达到好的可读性以便于交流以及起到备忘作用. 在批处理命令中如果不 ...
- 从你的u盘启动:30天自制操作系统第四天u盘启动学习笔记
暑假学习小日本的那本书:30天自制操作系统 qq交流群:122358078 ,更多学习中的问题.资料,群里分享 developing environment:ubuntu 关于u盘启动自己做的操 ...
- linux服务器上apache+php独立于mysql server单独部署
1. mysql client 2. libmysqlclient-devel 3. PDO_MYSQL