Codeforces Round #640 (Div. 4) A - Sum of Round Numbers Solution




 Solve in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,t,i,a,b,r;

    cin>>t;
    while(t--)
    {
        vector<int>v;
        r=1;
        cin>>n;
        while(n!=0)
        {
            r=r*10;
            a=n%r;
            n=n-a;
            if(a!=0)
                v.push_back(a);
        }
        cout<<v.size()<<endl;
        for(i=0; i<v.size(); i++)
        {
            cout<<v[i]<<" ";
        }
        cout<<endl;
    }
}

 

1 comment:

  1. //Java
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.Scanner;

    public class roundNum {

    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    LinkedList list = new LinkedList<>();
    int n = input.nextInt();
    int arr[] = new int[n];
    for (int i = 0; i < n; i++) {
    arr[i] = input.nextInt();
    }
    int mod, x = 1, count = 0;
    for (int i = 0; i < arr.length; i++) {
    while (arr[i] > 0) {
    x = x * 10;
    mod = arr[i] % x;
    if (mod != 0) {
    arr[i] = arr[i] - mod;
    count++;
    list.addFirst(mod);
    }
    }
    list.addFirst(count);
    Iterator itr = list.iterator();
    while (itr.hasNext()) {
    System.out.println(itr.next());
    }
    list.clear();
    count = 0;
    x = 1;
    }

    }

    }

    ReplyDelete

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.