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 :290 - Palindroms <---> smordnilaP

#include <bits/stdc++.h>
#define sc(a) scanf("%d",&a)
#define scd(a,b) scanf("%d%d",&a,&b)
#define sct(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define READ freopen ("in.txt","r",stdin)
#define MV 20
using namespace std;

typedef long long ll;

//typedef vector<string>vc;
//vector<vc>graph;
//graph.assign(r+2,vc());
int graph[1005][1005];
bool visited[1005][1005];
int xr[]= {-1,-1,-1,0,0,1,1,1};
int yc[]= {-1,0,1,-1,1,-1,0,1};
int rr[]= {0,-1,0,1};
int cc[]= {-1,0,1,0};
int b,cnt,x,y,z,rem;


void step( int base,string str)
{
    // cout<<str<<" ";
    int l=str.size();
    string s=str;
    reverse(s.begin(),s.end());

    string ans;
    // cout<<str<<" "<<s<<endl;
    for(int i=l-1; i>=0; i--)
    {
        char ch=str[i];
        if(ch=='E') x=14;
        else if(ch=='D') x=13;
        else if(ch=='C') x=12;
        else if(ch=='B') x=11;
        else if(ch=='A') x=10;
        else x=ch-'0';



        ch=s[i];
        if(ch=='E') y=14;
        else if(ch=='D') y=13;
        else if(ch=='C') y=12;
        else if(ch=='B') y=11;
        else if(ch=='A') y=10;
        else y=ch-'0';
        z=x+y+rem;
        rem=z/base;
        int d=z%base;

        if(d==14) ans+="E";
        else if(d==13) ans+="D";
        else if(d==12) ans+="C";
        else if(d==11) ans+="B";
        else if (d==10) ans+="A";
        else ans+=(d+'0');

    }
    if(rem>0)ans+=(rem+'0');
    reverse(ans.begin(),ans.end());
    // cout<<ans<<endl;
    string t=ans;
    reverse(t.begin(),t.end());
    // cout<<t<<endl;
    if(ans==t)
    {
        // cout<<endl;
        if(base!=15) cout<<" "<<cnt+1;
        else cout<<cnt+1;
        return ;
        // return cnt;
    }
    else
    {

        //cout<<ans<<endl;
        rem=0;
        cnt++;
        step( base,ans);
    }


}

int main()
{
   // READ;
   // freopen("out.txt","w",stdout);
    string str;
    while(cin>>str)
    {
        for(int base=15; base>=2; base--)
        {
            //if(base<15) cout<<" ";
            cnt=0;
            rem=0;

            string ss=str;
            sort(ss.begin(),ss.end());
            int l=ss.length();
            char ch=ss[l-1];
            if(ch=='E') b=14;
            else if(ch=='D') b=13;
            else if(ch=='C') b=12;
            else if(ch=='B') b=11;
            else if(ch=='A') b=10;
            else b=ch-'0';
            if(b>=base)
            {
                if(base<15) cout<<" ";
                printf("?");
                continue;

            }
            // cout<<cnt+1<<endl;

            string sss=str;
            reverse(sss.begin(),sss.end());
            if(sss==str)
            {

                if(base<15) cout<<" ";
                printf("0");
                continue;

            }

            step(base,str);

        }
        printf("\n");

    }


    return 0;
}

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

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