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 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.