kick start Round A 2022 Challenge Nine (8pts, 12pts) Solution




Problem Link :  https://codingcompetitions.withgoogle.com/kickstart/round/00000000008cb33e/00000000009e7997

 Solution 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,ts,i,t,add,sum,r,ogs;
    cin>>t;
    for(ts=1; ts<=t; ts++)
    {
        string s;
        sum=0;
        cin>>s;
        printf("Case #%d: ",ts);
        for(i=0; i<s.size(); i++)
        {
            sum+=s[i]-'0';
        }
        if(sum%9==0)
        {
            cout<<s[0]<<"0";
            if(s.length()>1)
            {
                s=s.substr(1);
                cout<<s;
            }
            cout<<endl;
        }
        else
        {
            add=9-sum%9;
            for(i=0; i<s.size(); i++)
            {
                if((s[i]-'0')> add)
                    break;
                else
                {
                    cout<<s[i];
                }
            }
            cout<<add;
            if(i<s.size())
            {
                s=s.substr(i);
                cout<<s;
            }
            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.