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

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

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