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 : 11221 - Magic square palindromes.

#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 N 8

using namespace std;

typedef long long ll;
typedef vector<int>vc;

int main()
{

   // freopen("input.txt","r",stdin);
    int test;
    sc(test);
    getchar();
    char arr[100][100];
    for(int cas=1; cas<=test; cas++)
    {
        string str;
        getline(cin,str);
        string ss;
        for(int i=0; i<str.size(); i++)
        {
            if(str[i]>='a'&&str[i]<='z') ss+=str[i];

        }
        int len=ss.size();
        //  cout<<ss<<endl;
        int d=sqrt(len);
        printf("Case #%d:\n",cas);
        if(d*d!=len)
        {
            puts("No magic :(");
            continue;

        }
        int r=0;
        for(int i=0; i<len; i+=d,r++)
        {

            for(int j=i,c=0; j<i+d; j++,c++)
            {

                arr[r][c]=ss[j];
            }

        }

        /* for(int i=0; i<d; i++)
         {
             for(int j=0; j<d; j++) cout<<arr[i][j];
             cout<<endl;

         }*/
        string a,b,x,y;
        // cout<<d<<endl;

        for(int i=0; i<d; i++)
        {
            for(int j=0; j<d; j++)
            {
                a+=arr[i][j];
                b+=arr[j][i];
            }


        }

         for(int i=d-1;i>=0;i--)
         {

             for(int j=d-1;j>=0;j--)
             {
                x+=arr[i][j];
                y+=arr[j][i];

             }

         }
       // cout<<a<<endl;
       // cout<<b<<endl;
       //cout<<x<<endl;
        //cout<<y<<endl;
        if(a==b&&a==x&&a==y&&b==x&&b==y&&x==y) cout<<d<<endl;
        else  puts("No magic :(");


    }

    return 0;
}

মঙ্গলবার, ৭ জুলাই, ২০১৫

C++ - std::vector add, insert, remove, process, erase, swap, sort, clear



Here is some examples of how to use std::vector with string for most of the common operations that can be performed on std::vector.

The following example assume the following has been declared



1
std::vector<std::string> vec;


Adding Items

1
2
3
4
5
vec.push_back("Item 1");
vec.push_back("Item 2");
vec.push_back("Item 3");
vec.push_back("Item 4");
vec.push_back("Item 5");

Adding Items to front

1
2
vec.insert(vec.begin(), "Front 2");
vec.insert(vec.begin(), "Front 1");

Remove Last Item

1
vec.pop_back();



Remove First Item

1
vec.erase(vec.begin());


Process All Items

1
2
3
4
for(std::vector<std::string>::iterator it = vec.begin(); it != vec.end(); it++)
{
  printf("%s\n", it->c_str());
}

Process All Items

1
2
3
4
for(size_t i = 0; i < vec.size(); i++)
{
  printf("%s\n", vec[i].c_str());
}

Reverse The Order - Note you can also just run the above backwards instead.

1
2
3
4
5
6
for(size_t i = 0; i < vec.size() / 2; i++)
{
  std::string tmp = vec[i];
  vec[i] = vec[vec.size() - i - 1];
  vec[vec.size() - i - 1] = tmp;
}

Sorting

1
std::sort(vec.begin(), vec.end());

Find and Remove an item

1
2
3
4
5
6
7
8
for(std::vector<std::string>::iterator it = vec.begin(); it != vec.end(); it++)
{
  if (*it == "Item 2")
  {
    vec.erase(it);
    break//it is now invalud must break!
  }
}

Clear All Items

1
vec.clear();

রবিবার, ৫ জুলাই, ২০১৫

UVA 11470 - Square Sums solution

#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 pi acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int>vc;

int xr[]= {-1,-1,-1,0,0,1,1,1};
int yc[]= {-1,0,1,-1,1,-1,0,1};

int row,col;

bool visit[102][102];

int main()
{
    //freopen("in.txt","r",stdin);
    int ary[11][11];
    int n,cas=0;
    while(~sc(n))
    {
        if(n==0) break;
        memset(visit,0,sizeof(visit));
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<n; j++) sc(ary[i][j]);
        }
        int limit=n/2;
        if(n%2!=0) limit++;
        printf("Case %d: ",++cas);

        for(int k=0,x=n; k<limit; k++,x--)
        {
            int sum=0;
            memset(visit,0,sizeof(visit));
            for(int i=k; i<x; i++)
            {

                if(visit[k][i]==0) sum+=ary[k][i];
                visit[k][i]=1;
                if(visit[i][k]==0)  sum+=ary[i][k];
                visit[i][k]=1;
                if(visit[x-1][i]==0) sum+=ary[x-1][i];
                visit[x-1][i]=1;
                if(visit[i][x-1]==0) sum+=ary[i][x-1];
                visit[i][x-1]=1;

            }
            cout<<sum;
            if(k<limit-1) printf(" ");

        }
        cout<<endl;

    }

    return 0;
}











UVA 11244 - Counting Stars solution

#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 pi acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int>vc;

int xr[]= {-1,-1,-1,0,0,1,1,1};
int yc[]= {-1,0,1,-1,1,-1,0,1};

int row,col;
char str[102][102];
//bool visit[102][102];

int main()
{
  //  freopen("in.txt","r",stdin);
    while(~scd(row,col))
    {
        if(row==0&&col==0) break;
       // memset(visit,0,sizeof(visit));
        for(int i=0; i<row; i++) cin>>str[i];
        int cnt=0;
        for(int i=0; i<row; i++)
        {
            for(int j=0; j<col; j++)
            {
                bool flag=false;
                if(str[i][j]=='*')
                {

                    for(int k=0; k<8; k++)
                    {
                        if(((i+xr[k])>=0&&(i+xr[k])<row)&&((j+yc[k])>=0&&(j+yc[k])<col))
                        {
                            int R=i+xr[k];
                            int C=j+yc[k];
                            if(str[R][C]=='*') flag=true;

                        }

                    }
                    if(flag==false) cnt++;

                }


            }


        }

        printf("%d\n",cnt);

    }

    return 0;
}











শুক্রবার, ৩ জুলাই, ২০১৫

UVA 10523 - Very Easy Solution

import java.util.Scanner;
import java.math.BigInteger;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while (input.hasNext()) {
            int n = input.nextInt();
            int a = input.nextInt();
            BigInteger A = BigInteger.valueOf(a);
            BigInteger sum = BigInteger.ZERO;
            for (int i = 1; i <= n; i++) {

                sum = sum.add(BigInteger.valueOf(i).multiply(A.pow(i)));

            }
            System.out.println(sum);

        }

    }

}