Codeforces 109A. Lucky Sum of Digits Solution

Solution in c++:
     ///**********ALLAH IS ALMIGHTY************///
     ///AH Tonmoy
    ///Department of CSE,23rd batch
    ///Islamic University,Bangladesh
#include<iostream>
using namespace std;
int  main()
{
    int sum,a,b,i,j;
    while(cin>>sum)
    {
        a=b=0;
        while(sum>0)
        {

            if(sum%7==0)
            {
                b++;
                sum-=7;
            }
            else if(sum%4==0)
            {
                a++;
                sum-=4;
            }
            else
            {
                a++;
                sum-=4;
            }
        }
        if (sum < 0)
        {
            printf("-1\n");
            break;
        }

        for (int i=0; i<a; i++)
            printf("4");

        for (int i=0; i<b; i++)
            printf("7");

        cout<<endl;

    }
}

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.