-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ8
23 lines (17 loc) · 951 Bytes
/
Q8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Problem statement:
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1≤n≤104). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Bug Code:
#include<bits/stdc++.h>
using namespace std;
int main(){
int T,n;cin>>T;
while(T--){
vector<int>v;
cin>>n;int m=10;
while(n){if(n%m)v.push_back(n/m),n-=n/m;m*=10;}
cout<<v.size()<<"\n";
for(auto x:v)cout<<x<<" ";puts("");
}
}