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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- Stage3D学习笔记(四):正交矩阵
我们上一章节显示图片的时候,会发现我们制定的顶点在Stage3D中其实是存在一个区间的: x轴(从左到右):[-1.0-1.0] y轴(从下到上):[-1.0-1.0] z轴(从近到远):[0-1.0 ...
- SQL 存储过程(学生,课程表,选修表)
SQL 存储过程(学生,课程表,选修表) 一.存储过程的分类 在SQL Server中存储过程分过两类: 1)系统存储过程("sp_"作为前缀) 2)用户自定义存储过程 二.创建和 ...
- iOS UDID和UUID详解
这篇是普及知识来了,纯属消遣时间,有需要的可以遛一遛. UDID的全名为 Unique Device Identifier :设备唯一标识符.从名称上也可以看出,UDID这个东西是和设备有关的,而且是 ...
- discuz!版本号信息改动步骤
建完网站后,就到了改动discuz! 论坛的步骤了,,将其改动为自己喜欢的样子.是非常有意思的,废话不多说了.以下给大家介绍改动的方法. 1.[改动后台-首页的版权]打开ftp.连接网站,进入到:/f ...
- Mysql 5.5 replication 多数据库主从备份Master-Slave配置总结
配置Mysql server 5.5 的双机备份,也就是master-slave模式.本例子还是一个多database复制的情况. 现在有两个database在同一台mysql server,也就是m ...
- 学通javaweb 24堂课 学习笔记
17.01:简单配置控制器 1.一个controller protected ModelAndView handleRequestInternal(HttpServletRequest request ...
- mysql语句在客户端与服务端的基本使用
//把数据库导出到脚本文件mysqldump -uroot -p1234 --databases abc > d:/a/abc.sql------------------------------ ...
- Java基础知识强化之IO流笔记68:Properties和IO流集合使用
1. Properties和IO流集合使用 这里的集合必须是Properties集合: public void load(Reader reader):把文件中的数据读取到集合中 public v ...
- ASP.NET 不同页面之间传值
不同页面之间如何传值?我们假设A和B两个页面,A是传递,B是接收. 下面学习4种方式: 通过URL链接地址传递 POST方式传递 Session方式传递 Application方式传递 1. 通过UR ...
- 第二次作业第2题_JH
2.每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令.比较项目的新旧版本的差别. (1)创建一个HelloWorld ...