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: 10189 - Minesweeper

#include<bits/stdc++.h>
#define READ freopen("in.txt","r",stdin);
#define WRITE freopen ("out.txt","w",stdout);
using namespace std;

int R[] = { -1, -1, -1, 0, 1, 1, 1, 0 };
int C[] = { -1, 0, 1, -1, -1, 0, 1, 1 };


int main()
{
   // READ WRITE
    int row, col,cas=0;
    char ary[101][101];
    while (~scanf("%d%d", &row, &col))
    {
        cas++;

        if (row == 0 && col == 0) break;
        if (cas != 1) printf("\n");


        for (int i = 0; i < row; i++) cin >> ary[i];

        printf("Field #%d:\n",cas);

        for (int i = 0; i < row; i++)
        {
            for (int j = 0; j < col; j++)
            {
                if (ary[i][j] == '*') continue;
                int count = 0;
                for (int k = 0; k < 8; k++) if (ary[i + R[k]][j + C[k]] == '*') count++;
                ary[i][j] = count+'0';
            }

        }

        for (int i = 0; i < row; i++) cout << ary[i] << endl;
        memset (ary,0,sizeof(ary));


    }

    return 0;
}

UVA SOLUTION:10935 - Throwing cards away I

#include<bits/stdc++.h>
#define READ freopen("in.txt","r",stdin);
#define WRITE freopen ("out.txt","w",stdout);
using namespace std;

int main()
{
   // READ
   // WRITE
    queue<int >Q;
    queue<int>r;
    int n;
    while(cin>>n)
    {
        if(n==0) break;
        if(n==1)
        {
           cout<<"Discarded cards:"<<endl;
           cout<<"Remaining card: 1"<<endl;
            continue;
        }
        while(!Q.empty()) Q.pop();
        while(!r.empty()) r.pop();
        for(int i=1; i<=n; i++) r.push(i);
        while(r.size()>1)
        {
            int u=r.front();
            Q.push(u) ;
            r.pop();
            int x=r.front();
            r.pop();
            r.push(x);

        }
        int c=0;
        cout<<"Discarded cards: ";
        while(!Q.empty())
        {
            cout<<Q.front();
            c++;
            if(c<n-1) cout<<", ";
            Q.pop();
        }
        cout<<endl;
        cout<<"Remaining card: "<<r.front()<<endl;

    }





    return 0;
}

UVA SOLUTION:11559 - Event Planning

//MH RIYAD
//lan:c++

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#include<stack>
#define inf 1<<31
using namespace std;


int main()
{  

vector<int>vc;
int ary[500];
int per, bud, hotel, week;
while (cin >> per >> bud >> hotel >> week)
{  
int weekendprice;
int p = 0;
while (hotel--)
{
cin>>weekendprice;
for (int i = 0; i < week; i++) cin >> ary[i];
for (int i = 0; i < week; i++)
{
if (ary[i] >= per)
{
p = 1;
vc.push_back(weekendprice*per);
break;

}

}


         }
//cout << vc[0] << endl;
if (p == 0) printf("stay home\n");
else
{
sort(vc.begin(), vc.end());
if (vc[0]>bud)
printf("stay home\n");
else cout << vc[0] << endl;
}


vc.clear();

}


return 0;
}

শুক্রবার, ১৬ জানুয়ারী, ২০১৫

Codeforces Beta Round #93 (Div. 2 Problem A)

//MH RIYAD
//facebook.com/riadzz

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;

class riyad
{
public:
double x;
double y;
};

double find_dis(double a, double b, double c, double d)
{
double res = sqrt(((a - c)*(a - c)) + ((b - d)*(b - d)));
return res;
}

int main()
{    

double n, k;
riyad ary[105];
while (~scanf("%lf %lf", &n, &k))
{
for (int i = 0; i < n; i++)
{
cin >> ary[i].x >> ary[i].y;
}
double sum = 0.0;
for (int i = 0; i < n-1; i++)
{
          sum= sum+ find_dis(ary[i].x, ary[i].y, ary[i+1].x, ary[i+1].y);

}
sum /= 50.0;
printf("%.9lf\n", sum*k);


}
// system("pause");
return 0;
}

সোমবার, ১২ জানুয়ারী, ২০১৫

SPOJ SOLUTION :11. Factorial

#define CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;

void findfactoralzero(long long num)
{  
int count = 0,n=1;
for (int i = 5;; i = i * 5)
{
if (num / i == 0) break;
count += num/i;

}
cout <<count<< endl;

}
int main()
{

int test;
long long num;
cin >> test;
while (test--)
{
cin >> num;
findfactoralzero(num);


}


return 0;
}

SPOJ SOLUTION :42. Adding Reversed Numbers

#include<bits/stdc++.h>

using namespace std;

int main()
{

    int test;
    char a[100],b[100],c[100],d[100],q[100],r[100];
    cin>>test;
    while(test--)
    {

        scanf("%s%s",a,b);
        int l1=strlen(a);
        int l2=strlen(b);
        int k=0;
        for(int i=l1-1; i>=0; i--) c[k++]=a[i];
        c[k++]='\0';
        k=0;
        for(int i=l2-1; i>=0; i--) d[k++]=b[i];
        d[k++]='\0';

        int x=atoi(c);
        int y=atoi(d);
       // cout<<x<<y<<endl;
        int res=x+y;
        //cout<<res<<endl;
        sprintf(q,"%d",res);
        int len=strlen(q);
        k=0;
        for(int i=len-1;i>=0;i--) r[k++]=q[i];
        r[k++]='\0';
        cout<<atoi(r)<<endl;


    }


    return 0;
}

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

SPOJ SOLUTION :452- Longest Common Subsequence

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include <ctime>

using namespace std;

char s1[1010],s2[1010],res[1010];
int icount[1010],jcount[1010],ary[1010][1010];

int lcs(int m,int n)
{
    // ary[m+1][n+1];
    for(int i=0; i<=m; i++)
    {
        for(int j=0; j<=n; j++)
        {
            if(i==0||j==0) ary[i][j]=0;
            else if(s1[i-1]==s2[j-1])  ary[i][j]=ary[i-1][j-1]+1;
            else ary[i][j]=max(ary[i-1][j],ary[i][j-1]);
        }
    }
    return ary[m][n];

}
void printlcs(int m,int n)
{

    int i=m,j=n;
    int index=-1;
    while(true)
    {
        if(s1[i-1]==s2[j-1])
        {
            index++;
            icount[index]=i;
            jcount[index]=j;
            res[index]=s1[i-1];
            i--;
            j--;
        }
        else
        {

            if( ary[i-1][j]>ary[i][j-1]) i--;
            else j--;
        }
        if(i==0||j==0) break;

    }
    for(int i=index; i>=0; i--)
    {
        printf("%c %d %d\n",res[i],icount[i],jcount[i]);
    }



}

int main()
{
    int test;
    scanf("%d",&test);
    for(int cas=1; cas<=test; cas++)
    {
        int l1,l2;
        scanf("%d%s%d%s",&l1,s1,&l2,s2);
        int res=lcs(l1,l2);
        if(res==0||res==1)
        {
            printf("case %d N\n",cas);
            continue;
        }
        printf("case %d Y\n",cas);
        cout<<res<<endl;
        printlcs(l1,l2);



    }

    return 0;
}

সোমবার, ৫ জানুয়ারী, ২০১৫

UVA solution : 10815 - Andy's First Dictionary

#include <iostream>
#include<cstdio>
#include<cstring>
#include<map>

using namespace std;
map<string,int>mep;
map<string,int>:: iterator it;
void stk(char *s)
{
    char *ptr=strtok(s," ");
    while(ptr!=NULL)
    {
        string p=ptr;
        if(mep[p]==0) mep[p]++;
        ptr=strtok(NULL," ");
    }
}

int main()
{
    char ss[300];
    char str[300];
    while(gets(ss))
    {
        if(ss[0]=='\0') continue;
        int l=strlen(ss);
        int j=0;
        for(int i=0; i<l; i++)
        {
            if(ss[i]>='A'&&ss[i]<='Z') ss[i]=tolower(ss[i]);
            if(!(ss[i]>='a'&&ss[i]<='z')||(ss[i]==' '))ss[i]=' ';
            str[j++]=ss[i];
        }
        str[j]='\0';
        stk(str);
    }

    for(it=mep.begin(); it!=mep.end(); it++) cout<<it->first<<endl;


    return 0;
}

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

UVA solution : 10066 - The Twin Towers

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;
vector<int>vc;
vector<int>vc2;
int lcs(int m,int n)
{
    int ar[m+1][n+1];
    for(int i=0;i<=m;i++){
        for(int j=0;j<=n;j++){
            if(i==0||j==0) ar[i][j]=0;
            else if(vc[i-1]==vc2[j-1]) ar[i][j]=ar[i-1][j-1]+1;
            else ar[i][j]=max(ar[i-1][j],ar[i][j-1]);
        }
    }
    return ar[m][n];
}

int main()
{
     int m,n,p,cas=0;
     while(~scanf("%d%d",&m,&n))
     {
         if(m==0&&n==0) break;
         for(int i=0;i<m;i++){cin>>p;vc.push_back(p);}
         for(int i=0;i<n;i++){cin>>p;vc2.push_back(p);}
         int res=lcs(m,n);
         printf("Twin Towers #%d\nNumber of Tiles : %d\n",++cas,res);
         vc.clear();vc2.clear();
         printf("\n");
     }

    return 0;
}

Uva solution : 10192- vacation

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;
int lcs(char *a,char *b,int m,int n)
{
    int ar[m+1][n+1];
    for(int i=0;i<=m;i++){
        for(int j=0;j<=n;j++){
            if(i==0||j==0) ar[i][j]=0;
            else if(a[i-1]==b[j-1]) ar[i][j]=ar[i-1][j-1]+1;
            else ar[i][j]=max(ar[i-1][j],ar[i][j-1]);
        }
    }

    return ar[m][n];

}
int main()
{
     char a[200],b[200];
     int cas=0;
     while(gets(a))
     {
          if(a[0]=='#') break;
         gets(b);
         int l1=strlen(a);
         int l2=strlen(b);
         int res=lcs(a,b,l1,l2);
         printf("Case #%d: you can visit at most %d cities.\n",++cas,res);
     }


    return 0;
}

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;
}

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

UVA SOLUTION : 10405 - Longest Common Subsequence

#include <iostream>
#include<cstdio>
#include<cstring>

using namespace std;
int maxi(int a,int b)
{
    return a>b?a:b;
}
int lcs(char *a,char *b,int m,int n)
{
    int ar[m+1][n+1],i,j;

    for( i=0; i<=m; i++)
    {
        for(j=0; j<=n; j++)
        {
            if(i==0||j==0)
            {
                ar[i][j]=0;
                continue;
            }
            else if(a[i-1]==b[j-1]) ar[i][j]=ar[i-1][j-1]+1;
            else if(a[i-1]!=b[j-1]) ar[i][j]=maxi(ar[i-1][j],ar[i][j-1]);

        }
    }

 return ar[m][n];

}

int main()
{
     //freopen("in.txt","r",stdin);
    char a[1009],b[1009];
    int l1,l2,res;
    while(gets(a))
    {
        gets(b);
        l1=strlen(a);
        l2=strlen(b);
        res=lcs(a,b,l1,l2);
        printf("%d\n",res);

    }




    return 0;
}

Uva solution :755 - 487--3279

#include <iostream>
#include<cstdio>
#include<cstring>
#include<map>

using namespace std;
map<char,char>m;
void pre()
{
    m['A']='2';m['B']='2';m['C']='2';m['G']='4';m['H']='4';m['I']='4';
    m['J']='5';m['K']='5';m['L']='5';m['M']='6';m['N']='6';m['O']='6';
    m['P']='7';m['R']='7';m['S']='7';m['T']='8';m['U']='8';m['V']='8';
    m['W']='9';m['X']='9';m['Y']='9';
}

int main()
{
    pre();
    map<string,int>mep;
    map<string,int>::iterator it;
    int test,h;
    char ss[100];
    scanf("%d\n",&test);
    for(int cas=1; cas<=test; cas++)
    {

        scanf("%d",&h);
        getchar();
        while(h--)
        {
            gets(ss);
            int t=0;
            string str,res;
            int len=strlen(ss);
            for(int i=0; i<len; i++)
            {
                if(ss[i]!='-')
                {
                    ++t;
                    str+=ss[i];
                    if(t==3) str+='-';

                }
            }
            char p;
            for(int i=0; i<str.size(); i++)
            {
                if(str[i]>='A'&&str[i]<='Z')
                {
                    p=m[str[i]];

                }
                else p=str[i];
                res+=p;
            }
            mep[res]++;

        }

        bool flag=false;
        for(it=mep.begin(); it!=mep.end(); it++)
        {
            if((it->second)>1)
            {
                cout<<it->first<<" "<<it->second<<endl;
                flag=true;
            }
        }

        if(flag==false) printf("No duplicates.\n");
        mep.clear();

        if(cas!=test) printf("\n");
    }

    return 0;
}

UVA solution : 11988 - Broken Keyboard (a.k.a. Beiju Text)

#include<cstdio>
#include<cstring>
#include<list>
#include<iostream>
#define READ freopen("in.txt","r",stdin);
using namespace std;

int main()
{
   // READ
    list<char>l;
    list<char>::iterator it;
    string ss;
    while(cin>>ss)
    {
        it=l.begin();
        for(int i=0; i<ss.size(); i++)
        {

            if(ss[i]=='[') it=l.begin();
            else if(ss[i]==']') it=l.end();
            else l.insert(it,ss[i]);

        }

        for(it=l.begin(); it!=l.end(); it++) cout<<*it;
        printf("\n");
        l.clear();

    }

    return 0;
}

UVA SOLUTION: 10424 - Love Calculator

#include <iostream>
#include<cstdio>
#include<cstring>

using namespace std;
double fun(int s1,int s2)
{
    while(s1>9)
    {
        int res=0;
        while(s1)
        {
            res+=(s1%10);
            s1/=10;
        }
        s1=res;

    }
    while(s2>9)
    {
        int res=0;
        while(s2)
        {
            res+=(s2%10);
            s2/=10;
        }
        s2=res;

    }

    // cout<<s1<<" "<<s2<<endl;
    double r;
    if(s1<s2)
    {
        r=(double)s1/(double)s2;
        r*=100;
    }
    else  if(s1>s2)
    {
        r=(double)s2/(double)s1;
        r*=100;
    }
    else
    {
        r=100.00;
    }

    return r;
}

int main()
{

    string s1,s2;
    while(getline(cin,s1))
    {
         getline(cin,s2);
        int l1=s1.size();
        int l2=s2.size();
        int sum1=0,sum2=0;
        for(int i=0; i<l1; i++)
        {
            if((s1[i]>='a'&&s1[i]<='z')||(s1[i]>='A'&&s1[i]<='Z'))
            {
                if (s1[i]>='a'&&s1[i]<='z') sum1+=(s1[i]-96);
                if(s1[i]>='A'&&s1[i]<='Z') sum1+=(s1[i]-64);
            }
        }
        for(int i=0; i<l2; i++)
        {
            if((s2[i]>='a'&&s2[i]<='z')||(s2[i]>='A'&&s2[i]<='Z'))
            {
                if (s2[i]>='a'&&s2[i]<='z') sum2+=(s2[i]-96);
                if(s2[i]>='A'&&s2[i]<='Z') sum2+=(s2[i]-64);
            }
        }
        // cout<<sum1<<sum2<<endl;
        char x='%';
        double res=fun(sum1,sum2);
        printf("%.2lf %c\n",res,x);

    }


    return 0;
}

শুক্রবার, ২ জানুয়ারী, ২০১৫

UVA SOLUTION : 11233 - Deli Deli

#include <iostream>
#include<cstdio>
#include<cstring>
#include<map>
#define READ freopen("in.txt","r",stdin);

using namespace std;

int main()
{
   // READ
    map<string,string>mep;
    int L,N;
    scanf("%d%d",&L,&N);
    while(L--)
    {
        string a,b;
        cin>>a>>b;
        mep[a]=b;
    }
    while(N--)
    {
        string s;
        cin>>s;
        int len=s.size();
        string  pp=mep[s];
        if(pp[0]!='\0')
        {
            string res=mep[s];
            cout<<res;
        }
        else if(s[len-1]=='y')
        {

            if(s[len-2]=='a'||s[len-2]=='e'||s[len-2]=='i'||s[len-2]=='o'||s[len-2]=='u')cout<<s<<"s";
            else
            {
                string res=s.substr(0,len-1);
                cout<<res<<"ies";
            }
        }
        else if(s[len-1]=='o'||s[len-1]=='s'||s[len-1]=='x'||(s[len-2]=='c'&&s[len-1]=='h')||(s[len-2]=='s'&&s[len-1]=='h'))
        {
            cout<<s<<"es";
        }
        else
        {
            cout<<s<<"s";
        }
        printf("\n");
    }

    return 0;
}

UVA SOLUTION : 10361 Automatic poetry


#include <iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
   // freopen("in.txt","r",stdin);
    string s,r,s2,s4,s3,s5;
    int test;
    cin>>test;
    getchar();
    while(test--)
    {
        getline(cin,s);
        getline(cin,r);
        int cn=0,flag=0;
        for(int i=0; i<s.size(); i++)
        {

            if(s[i]=='<')
            {

                flag=1;
                cn++;

            }
            if(s[i]=='>')
            {
                flag=0;
            }
            if(flag==1)
            {
                if(cn==1)
                {
                    if(s[i]!='<')s2+=s[i];
                }
                else
                {
                    if(s[i]!='<') s4+=s[i];
                }
            }

        }

        cn=0;
        flag=0;
        for(int i=0; i<s.size(); i++)
        {

            if(s[i]=='>')
            {

                flag=1;
                cn++;

            }
            if(s[i]=='<')
            {
                flag=0;
            }
            if(flag==1)
            {
                if(cn==1)
                {
                    if(s[i]!='>')s3+=s[i];
                }
                else
                {
                    if(s[i]!='>') s5+=s[i];
                }
            }

        }
        for(int i=0; i<s.size(); i++) if(s[i]!='>'&&s[i]!='<') putchar(s[i]);
        printf("\n");
        for(int i=0; i<r.size(); i++)
        {
            if(r[i]=='.')
            {
                cout<<s4<<s3<<s2<<s5;
                break;
            }
            else putchar(r[i]);
        }

        printf("\n");
        s2.clear();
        s3.clear();
        s4.clear();
        s5.clear();
        //cout<<s2<<" "<<s4<<" "<<s3<<" "<<s5<<endl;
    }


    return 0;
}

বৃহস্পতিবার, ১ জানুয়ারী, ২০১৫

UVA solution :11787 - Numeral Hieroglyphs

#include <iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
     //freopen("in.txt","r",stdin);
    int test,ary[600],b,u,s,p,f,t,m;
    string ss;
    scanf("%d",&test);
    while(test--)
    {
        cin>>ss;
        int len=ss.length();
        b=0;
        u=0;
        s=0;
        p=0;
        f=0;
        t=0;
        m=0;
        int in=0,cnt=0;
        long long sum=0;
        for(int i=0; i<len; i++)
        {
            if(ss[i]=='B')
            {
                b++;
                ary[in++]=1;
                sum+=1;
            }
            else  if(ss[i]=='U')
            {
                u++;
                ary[in++]=2;
                sum+=10;
            }
            else  if(ss[i]=='S')
            {
                s++;
                ary[in++]=3;
                sum+=100;
            }
            else  if(ss[i]=='P')
            {
                p++;
                ary[in++]=4;
                sum+=1000;
            }
            else  if(ss[i]=='F')
            {
                f++;
                ary[in++]=5;
                sum+=10000;
            }
            else  if(ss[i]=='T')
            {
                t++;
                ary[in++]=6;
                sum+=100000;
            }
            else  if(ss[i]=='M')
            {
                m++;
                ary[in++]=7;
                sum+=1000000;
            }


        }
        int as=0,ds=0;
        for(int i=0; i<in-1; i++)
        {
            if(ary[i]>ary[i+1]) ds++;
            else if(ary[i]<ary[i+1]) as++;
        }


        if(as>0||(as==0&&ds==0))
        {
            for(int i=0; i<in; i++)
            {
                for(int j=0; j<in-1; j++)
                {
                    if(ary[j]>ary[j+1]) cnt++;
                }
            }
        }
        else if(ds>0)
        {
            for(int i=0; i<in; i++)
            {
                for(int j=0; j<in-1; j++)
                {
                    if(ary[j]<ary[j+1]) cnt++;
                }
            }


        }

        if(cnt>0||b>9||u>9||s>9||p>9||f>9||t>9||m>9)
         {
             printf("error\n");
         }
         else
         {
             cout<<sum<<endl;
         }



    }


    return 0;
}