Codeforces Round #300 - Quasi Binary(贪心)

Quasi Binary
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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

Input
9
Output
9
1 1 1 1 1 1 1 1 1 
Input
32
Output
3
10 11 11 

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
char str[10];
int main()
{
    int max_cnt;
    int first;
    while(~scanf("%s",str)){
        int len=strlen(str);
        max_cnt=0;
        for(int i=0;i<len;i++){
            max_cnt=max(max_cnt,str[i]-'0');
        }
        printf("%d\n",max_cnt);
        for(int i=0;i<max_cnt;i++){
            first=0;
            for(int j=0;j<len;j++){
                if(!first){
                    if(str[j]!='0'){
                        printf("1");
                        str[j]--;
                        first=1;
                    }
                }
                else{
                    if(str[j]!='0'){
                        printf("1");
                        str[j]--;
                    }
                    else{
                        printf("0");
                    }
                }
            }
            printf(" ");
        }
        puts("");
    }
    return 0;
}


已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页
实付 9.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值