Welcome

>>>Welcome to my "CODE BAZAR"
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others

Update ✔✔✔ Upcoming programming book (.pdf) "Programming Contest (data structures and algorithms) by Md. Mahbub Hasan & "Graph Algorithms" by Safayat Asraf "****** Date: 20 March, 2019****Hazrat Ali****

Monday 31 October 2016


V. Array Again
বলে রাখি, আমি ইচ্ছে করে এই কোডে একটি bug রেখেছি  আপনারা জাস্ট debug  করে উপলোড দিবেন or for RIGHT answer ক্লিক হেয়ার 

Problem link Click here


Score: 1

CPU: 1s
Memory: 512MB

You will be given a grid of size n*n. Then you will be given n*n numbers of the grid. Now you have to print the numbers of grid in spiral way.
Suppose you have a grid of size 3 * 3 and the given numbers are 1 2 3 4 5 6 7 8 9. Then the number will be in the grid like below.
1 2 3
4 5 6
7 8 9 
Now you have to print numbers as 1 2 3 6 9 8 7 4 5
Input
First you will be given an positive integer T (1< T <= 40), the number of test case. For each test case you will be given n( 0 < n < 50 ), the size of the grid. Then there will be n lines, each containing n numbers. No numbers will be greater than 9.

Output
Output For each test case you have to print “Case X: ”, where X is the number of test case and n*n numbers separated by a single space in spiral order, from top left side of the grid.

Sample

InputOutput
1 3 1 2 3 4 5 6 7 8 9 Case 1: 1 2 3 6 9 8 7 4 5



Solution

#include <stdio.h>
int main()
{
    int row,t,i, col, n, matrix[49][49];
    scanf("%d",&t);
    for(i=1;i<=t;i++){
    scanf("%d", &n);
    for(row = 1; row <= n; row++){
        for(col = 1; col <= n; col++){
            scanf("%d", &matrix[row][col]);
        }
    }
    row = 1;
    printf("Case %d:",i);
    while(n > 0){
        for(col = row; col <= n; col++){
            printf(" %d",matrix[row][col]);
        }
        for(col = row+1; col <= n; col++){
            printf(" %d", matrix[col][n]);
        }
        for(col = n-1; col > row-1; col--){
            printf(" %d", matrix[n][col]);
        }
        for(col = n-1; col > row; col--){
            printf(" %d", matrix[col][row]);
        }
        row++;
        n--;
    }
    printf("\n");
    }
    return 0;
}


Z. Point and the Circle
Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/Z


Score: 1

CPU: 1s
Memory: 512MB

Suppose you have a circle which has the center x, y and the radius of the circle is r. There is another point G (x1,y1). You have to find out that, whether the point is inside the circle or outside the circle. 

Input
First you will be given an positive integer T (1< T < 100), the number of test case. For each test case you will be given r, x, y, x1and y1 (-1000 < x, y, x1, y1 < 1000 ) in different lines.
Output
For each test case first you have to print “Case #:”, where # is the case number. Then if point G is inside the circle then print “YES” and “NO” if not

Sample

InputOutput
2 5 0 0 5 0 10 0 0 5 5Case 1: NO Case 2: YES

Solution

#include<stdio.h>
#include<math.h>
int main()
{
    double x,y,r,a,b,res=0;
    int i,n;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%lf%lf%lf%lf%lf",&r,&a,&b,&x,&y);
        res=sqrt((a-x)*(a-x)+(b-y)*(b-y));
        if(res<r){
            printf("Case %d: YES\n",i);
        }
        else{
            printf("Case %d: NO\n",i);
        }
    }

    return 0;
}


Y. The Great Prime
Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/Y


Score: 1

CPU: 1s
Memory: 512MB

Given N you have to find out whether N is a prime number or not. If you don’t know what a prime is, then read about Prime here.

Input
First you will be given an positive integer T (1< T < 100), the number of test case. For each test case you will be given N( 0 < N < 1000 ) in different lines.

Output
For each test case first you have to print “Case X:”, where X is the case number. Then if N is prime then print “YES” and “NO” if not prime.

Sample

InputOutput
4 5 9 19 25Case 1: YES Case 2: NO Case 3: YES Case 4: NO


Solution

#include<math.h>
#include<stdio.h>
int main()
{
    int f,h,s,e,i,b;
    scanf("%d",&s);
    for(f=1;f<=s;f++)
    {
        scanf("%d",&h);
        e=sqrt(h);
        b=0;
        for(i=2;i<=e;i++)
        {
            if(h%i==0)
            {
                printf("Case %d: NO\n",f);
                b++;
                break;
            }
        }
        if(b==0)
        {
            printf("Case %d: YES\n",f);
        }
    }
    return 0;
}


X. Simple Math
Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/X


Score: 1

CPU: 1s
Memory: 512MB

Recently a Mathematics contest held on Saint Martin Island where only one problem was given to the participants. Unfortunately all the contestants have solved the problem. So they all win the competition. But only T number of trophies will be given to the winners. Now as all of them won the contest. How many ways we can give T trophies to N participants, where T is always smaller than N

Input
First you will be given an positive integer X (1< X < 100), the number of test case. One line for each test case. For each test case you will be given two space separated integers N and T ( 1 <= T < N < 20 )

Output
For each test case you have to print “Case X: W”, where X is the case number and W is the number of ways we can give T trophies to N participants.

Sample

InputOutput
2 9 3 5 4Case 1: 504 Case 2: 120

Solution

#include<stdio.h>
int main()
{
    int i,j,k,a,b,n;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        long long res1=0,res2=1,res3=1,res=0;
        scanf("%d%d",&a,&b);
        for(j=1;j<=a;j++){
                res2=res2*j;
        }
        res1=a-b;
        for(k=1;k<=res1;k++){
            res3=res3*k;
        }
        res=res2/res3;
        printf("Case %d: %lli\n",i,res);
    }
    return 0;
}


W. Simple Array

Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/W


Score: 1

CPU: 1s
Memory: 512MB

You will be given a grid of size n*n. Then you will be given n*n numbers of the grid. Now you have to print the number of grid from last column to first column of row n, then the numbers from last column to first column to row n-1 and in such way till row 1 . 

Suppose you have a grid of size 3 * 3 and the given numbers are 1 2 3 4 5 6 7 8 9. Then the number will be in the grid like below.
1 2 3
4 5 6
7 8 9 
Now your result will be 9 8 7 6 5 4 3 2 1 

Input
First you will be given a positive integer T (1< T <= 40), the number of test case. For each test case you will be given N( 0 < N < 50 ). Then in next lines there will be n*n positive integers separated by single space. No numbers will be greater than 1000.

Output
For each test case you have to print n*n numbers in reverse order separated by a single space.

Sample

InputOutput
2 3 1 2 3 4 5 6 7 8 9 5 5 4 1 2 6 9 8 7 4 5 5 6 4 7 8 1 2 3 6 5 4 5 6 9 79 8 7 6 5 4 3 2 1 7 9 6 5 4 5 6 3 2 1 8 7 4 6 5 5 4 7 8 9 6 2 1 4 5



Solution

#include<stdio.h>
int main()
{
    int i,j,k,t,n,ara[51][51];
    scanf("%d",&t);
    for(i=1;i<=t;i++){
        scanf("%d",&n);
        for(j=0;j<n;j++){
            for(k=0;k<n;k++)
                scanf("%d",&ara[j][k]);
        }
        for(j=n-1;j>=n-1;j--)
            for(k=n-1;k>=n-1;k--)
            printf("%d",ara[j][k]);
        for(j=n-1;j>=n-1;j--)
            for(k=n-2;k>=0;k--)
                printf(" %d",ara[j][k]);
        for(j=n-2;j>=0;j--){
            for(k=n-1;k>=0;k--)
                printf(" %d",ara[j][k]);
            }
        printf("\n");
    }
        return 0;
}

U. Difficult Array

Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/U


Score: 1

CPU: 1s
Memory: 512MB

You will be given n integers. You have to print them in reverse order.
Input
First you will be given an positive integer T (1< T < 100), the number of test case. 
For each test case you will be given N( 0 < N < 1000 ). Then in next lines there will be n positive integers separated by single space. 
Output
For each test case you have to print n numbers in reverse order.

Sample

InputOutput
2 5 8 9 4 6 7 10 1 2 3 4 5 6 7 8 9 10 7 6 4 9 8 10 9 8 7 6 5 4 3 2 1

Solution

#include<stdio.h>
int main()
{
    int i,j,k,t,n,r[1005];
    scanf("%d",&t);
    for(i=1;i<=t;i++){
        scanf("%d",&n);
        for(j=0;j<n;j++){
            scanf("%d",&r[j]);
            }
            printf("%d",r[n-1]);
            for(j=n-2;j>=0;j--){
                printf(" %d",r[j]);
            }
        printf("\n");
    }

    return 0;
}

T. Awesome Rectangle

Prolem link
Score: 1

CPU: 1s
Memory: 512MB

Given N you have to draw N rectangle. Where
Length of rectangle will be = 9
Height of the rectangle will be = 4

If N = 1
*********
*       *
*       *
*********
If N=2
********* *********
*       * *       *
*       * *       *
********* ********* 
If N=3
********* ********* *********
*       * *       * *       *
*       * *       * *       *
********* ********* *********
There will be 1 space equal distance between two consecutive rectangle. 

Input
First you will be given an positive integer T (1< T < 100), the number of test case.
For each test case you will be given N(1<= N <= 100) in different lines.
Output
For each test case you have to print N rectangle in each line as shown in the description. There will be 1 space equal distance between two consecutive rectangle in the same line.

Sample

InputOutput
2 2 1********* ********* * * * * * * * * ********* ********* ********* * * * * *********

Solution

#include<stdio.h>
int main()
{
    int i,j,n,k,l,t;
    scanf("%d",&t);
    for(l=1;l<=t;l++){
    scanf("%d",&n);
    for(k=1;k<=4;k++){
        for(i=1;i<=n;i++){
            for(j=1;j<=9;j++)
                if(k!=1 && k!=4 && j!=1 && j!=9){
                    printf(" ");
            }
            else
                {
                printf("*");
            }
            if(i<n)
            printf(" ");
        }
        printf("\n");
    }
    }
        return 0;
}

S. Wave Form

Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/S

Score: 0

CPU: 1s
Memory: 512MB

You will be given n. You have to draw following figures.
If n == 1
*
If n == 2
 *
***
 *
If n == 3
  *
 ***
*****
 ***
  *


Input
First you will be given a positive integer T (1< T < 100), the number of test case. There will be T line next. Each line contains a single integer n ( 0 < n < 50 )

Output
For each n you have to draw figures as described in problem statement. Print a blank line between consecutive test cases.

Sample

InputOutput
3 1 2 3 * * *** * * *** ***** *** *

Solution

#include<stdio.h>
int main()
{
    int i,s=1,t,j,l,n;
    scanf("%d",&t);
    for(i=1;i<=t;i++){
        scanf("%d",&n);
        s=n-1;
        for(j=1;j<=n;j++){
            for(l=1;l<=s;l++)
                printf(" ");
                s--;
            for(l=1;l<=2*j-1;l++)
                printf("*");
            printf("\n");
        }
        s=1;
        for(j=1;j<=n-1;j++){
            for(l=1;l<=s;l++)
                printf(" ");
            s++;
            for(l=1;l<=2*(n-j)-1;l++)
                printf("*");
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

R. Pyramid

Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/R

Score: 1

CPU: 1s
Memory: 512MB

You will be givenn. You have to draw a * Pyramid of height n.
If n == 1
*
If n == 2
 *
***
If n == 3
  *
 ***
*****

Input
First you will be given a positive integer T (1< T < 100), the number of test case. There will be Tline next. Each line contains a single integer n ( 0 < n < 50 ).
Output
For each n you have to draw a Pyramid of heightn as described in problem statement. There will be blank line between consecutive test cases.

Sample

InputOutput
3 1 2 3 * * *** * *** *****

Solution

#include<stdio.h>
int main()
{
    int D,A,S,Y,W,C,X;
    scanf("%d",&W);
    for(D=1;D<=W;D++){
        if(D!=1){
            printf("\n");
        }
        scanf("%d",&X);
        C=X;
        for(A=1;A<=X;A++){
            for(S=1;S<C;S++){
                printf(" ");
            }
            C--;
            for(Y=1;Y<=2*A-1;Y++){
                printf("*");
            }
            printf("\n");
        }
   }
   return 0;
}
Q. 3 and 7


Problem link

Score: 1

CPU: 1s
Memory: 512MB

Given N you have to find out whether N is divisible by 3 and 7 or not.
Input
First you will be given an positive integer T (1< T < 100), the number of test case. For each test case you will be given N( 1 < N < 1000) in different lines.

Output
For each test case you have to print “N is divisible by 3” if N is divisible by 3 and “N is not divisible by 3” if N is not divisible by 3. After that if N is divisible by 3 then if N is also divisible by 7 then you have to print one extra line “N is also divisible by 7”. See the sample i/o for better understandings.

Sample

InputOutput
3 9 21 25 9 is divisible by 3 21 is divisible by 3 21 is also divisible by 7 25 is not divisible by 3

Solution

#include<stdio.h>
int main()
{
    int a,b,i;
    scanf("%d",&a);
    for(i=1;i<=a;i++){
        scanf("%d",&b);
        if(b%3==0){
            printf("%d is divisible by 3\n",b);
            if(b%7==0){
                printf("%d is also divisible by 7\n",b);
            }
        }
        else{
            printf("%d is not divisible by 3\n",b);
        }
    }
    return 0;
}

P. Divisible by 3

Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/P

Score: 1

CPU: 1s
Memory: 512MB

Given N you have to find out the total number of integer between 0 to N is divisible by 3.

Input
First you will be given an positive integer T (1< T < 100), the number of test case. For each test case you will be given N ( 1 < N < 1000) in different lines.

Output
For each test case print “Case X: R”. Where X is the running test case number and R is the total amount of integer divisible by 3between 0 and N .

Sample

InputOutput
3 6 9 12Case 1: 3 Case 2: 4 Case 3: 5

Solution

#include<stdio.h>
int main()
{
    int count,n,i,j,t;
    scanf("%d",&t);
    for(j=1;j<=t;j++){
        count=0;
        scanf("%d",&n);
        for(i=0;i<=n;i++){
            if(i%3==0){
                count++;
            }
        }
        printf("Case %d: %d\n",j,count);
    }
    return 0;
}

Sunday 30 October 2016

N. Loop

Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/N

Score: 1

CPU: 1s
Memory: 512MB

Given n, you have to print n to 1.
Suppose n = 5. Then you have to print 5, 4, 3, 2, 1.
Input
You will be given a positive integer n (1<=n<=1000).
Output
You have to print from n to 1 in n lines. Please see the sample i/o for better understanding.

Sample

InputOutput
55 4 3 2 1

Solution

#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    if(n>=1 && n<=1000){
        for(i=n;i>=1;i--){
            printf("%d\n",i);
        }
    }
    return 0;
}