About Me

About Me : I have been working as a Software Engineer for various international companies for four years.Currently, I am working as a full stack Javascript developer in Petronas(Malaysia).

Skills

Skills • Javascript •Typescript •Python •C •Java •ReactJs • Redux • VueJs • NestJs • React Testing Library • Django• PostgreSQL • MySQL • NodeJs • Git • Docker • Jira • Visual Studio Code • Slack

রবিবার, ৪ জানুয়ারী, ২০১৫

UVA SOLUTION : 263-Number Chains

#include <iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<math.h>
#include<map>
#include<algorithm>
#define READ freopen("in.txt","r",stdin);
#define WRITE freopen ("output.txt","w",stdout);

using namespace std;

int main()
{
   // READ WRITE
    map<int,int>mep;
    int n;
    while(~scanf("%d",&n))
    {
        if(n==0) break;
        char ss[50];
        char des[50];
        int cnt=0;
        printf("Original number was %d\n",n);
        while(1)
        {
            if(n==0) break;
            sprintf(ss,"%d",n);
            int l=log10(n)+1;
            sort(ss,ss+l);
            int j=0;
            for(int i=l-1; i>=0; i--) des[j++]=ss[i];
            des[j]='\0';
            int x=atoi(ss);
            int y=atoi(des);
            int res;
            res=y-x;
            printf("%d - %d = %d\n",y,x,res);
            if(mep[res]==1)
            {
                cnt++;
                break;
            }
            else
            {
                mep[res]++;
                cnt++;
                n=res;
            }
        }
        if(n==0)
        {
            printf("0 - 0 = 0\n");
            cnt++;
        }
        printf("Chain length %d\n",cnt);
        printf("\n");
        mep.clear();

    }

    return 0;
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন