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****

Thursday 24 November 2016

For test

Daffodil International University, Dhaka.




BSc in Computer Science and Engineering

Monday 14 November 2016

URI-1040

URI Online Judge | 1040

Average 3

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read four numbers (N1, N2, N3, N4), which one with 1 digit after the decimal point, corresponding to 4 scores obtained by a student. Calculate the average with weights 2, 3, 4 e 1 respectively, for these 4 scores and print the message "Media: " (Average), followed by the calculated result. If the average was 7.0 or more, print the message "Aluno aprovado." (Approved Student). If the average was less than 5.0, print the message: "Aluno reprovado." (Reproved Student). If the average was between 5.0 and 6.9, including these, the program must print the message "Aluno em exame." (In exam student).
In case of exam, read one more score. Print the message "Nota do exame: " (Exam score) followed by the typed score. Recalculate the average (sum the exam score with the previous calculated average and divide by 2) and print the message “Aluno aprovado.” (Approved student) in case of average 5.0 or more) or "Aluno reprovado."(Reproved student) in case of average 4.9 or less. For these 2 cases (approved or reproved after the exam) print the message "Media final: " (Final average) followed by the final average for this student in the last line.

Input

The input contains four floating point numbers that represent the students' grades.

Output

Print all the answers with one digit after the decimal point.
Input SampleOutput Sample
2.0 4.0 7.5 8.0
6.4
Media: 5.4
Aluno em exame.
Nota do exame: 6.4
Aluno aprovado.
Media final: 5.9
2.0 6.5 4.0 9.0Media: 4.8
Aluno reprovado.
9.0 4.0 8.5 9.0Media: 7.3
Aluno aprovado.

Solutin...

#include <stdio.h>
int main()
{
    double a, b, c, d, e, m;
    scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
    m = (a * 2 + b * 3 + c * 4 + d) / 10;
    printf("Media: %.1f\n", m);
    if (m >= 7.0){
        printf("Aluno aprovado.\n");
    }
    else if (m >= 5.0)
    {
        printf("Aluno em exame.\n");
        scanf("%lf", &e);
        printf("Nota do exame: %.1f\n", e);
        if (e + m / 2.0 > 5.0){
            printf("Aluno aprovado.\n");
        }
        else{
            printf("Aluno reprovado.\n");
        }
        printf("Media final: %.1f\n", (e + m) / 2.0);
    }
    else{
        printf("Aluno reprovado.\n");
    }
    return 0;
}


URI-1074

URI Online Judge | 1074

Even or Odd

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read an integer value N. After, read these N values and print a message for each value saying if this value is oddevenpositive or negative. In case of zero (0), although the correct description would be "EVEN NULL", because by definition zero is even, your program must print only "NULL", without quotes.

Input

The first line of input is an integer (< 10000), that indicates the total number of test cases. Each case is a integer number (-107 < X <107)..

Output

For each test case, print a corresponding message, according to the below example. All messages must be printed in uppercase letters and always will have one space between two words in the same line.
Input SampleOutput Sample
4
-5
0
3
-4
ODD NEGATIVE
NULL
ODD POSITIVE
EVEN NEGATIVE

Solution...

#include<stdio.h>
int main()
{
    int t,n,i;
    scanf("%d",&t);
    for(i=1;i<=t;i++){
        scanf("%d",&n);
        if(n%2!=0){
            if(n>0){
                printf("ODD POSITIVE\n");
            }
            else if(n<0){
                printf("ODD NEGATIVE\n");
            }
        }
        if(n%2==0){
            if(n>0){
                printf("EVEN POSITIVE\n");
            }
            else if(n<0){
                printf("EVEN NEGATIVE\n");
            }
        }
        if(n==0){
            printf("NULL\n");
        }
    }
    return 0;
}

URI-1073

URI Online Judge | 1073

Even Square

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read an integer N. Print the square of each one of the even values from 1 to including if it is the case.

Input

The input contains an integer (5 < < 2000).

Output

Print the square of each one of the even values from 1 to N, as the given example.
Be carefull! Some language automaticly print 1e+006 instead 1000000. Please configure your program to print the correct format setting the output precision.
Input SampleOutput Sample
62^2 = 4
4^2 = 16
6^2 = 36
 

Solution....

#include<stdio.h>
int main()
{
    int a,i,sum=0;
    scanf("%d",&a);
    for(i=2;i<=a;i=i+2){
        sum=i*i;
        printf("%d^2 = %d\n",i,sum);
    }
    return 0;
}

URI-1071

URI Online Judge | 1071

Sum of Consecutive Odd Numbers I

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read two integer values and Y. Print the sum of all odd values between them.

Input

The input file contain two integer values.

Output

The program must print an integer number. This number is the sum off all odd values between both input values that must fit in an integer number.
Sample InputSample Output
6
-5
5
15
12
13
12
12
0

Solution...

#include<stdio.h>
int main()
{
    int a,i,b,sum=0;
    scanf("%d%d",&a,&b);
    if(a%2==0){
        for(i=a-1;i>b;i=i-2){
            sum=sum+i;
        }

    }
    if(a%2!=0){
        for(i=a-2;i>b;i=i-2){
            sum=sum+i;
        }
    }
    printf("%d\n",sum);
    return 0;
}

URI-1070

URI Online Judge | 1070

Six Odd Numbers

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read an integer value and print the 6 consecutive odd numbers from X, a value per line, including if it is the case.

Input

The input will be a positive integer value.

Output

The output will be a sequence of six odd numbers.
Input SampleOutput Sample
89
11
13
15
17
19

Solution...

#include<stdio.h>
int main()
{
    int a,i,j=0;
    scanf("%d",&a);
    if(a%2==0){
        for(i=a+1;j<6;i=i+2){
            printf("%d\n",i);
            j++;
        }

    }
    if(a%2!=0){
        for(i=a;j<6;i=i+2){
            printf("%d\n",i);
            j++;
        }
    }
    return 0;
}

URI-1067

URI Online Judge | 1067

Odd Numbers

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read an integer value (1 <= <= 1000).  Then print the odd numbers from 1 to X, each one in a line, includingif is the case.

Input

The input will be an integer value.

Output

Print all odd values between 1 and X, including if is the case.
Input SampleOutput Sample
81
3
5
7

Solution...

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

URI-1066

URI Online Judge | 1066

Even, Odd, Positive and Negative

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Make a program that reads five integer values. Count how many   of these values are even, odd, positive and negative. Print these information like following example.

Input

The input will be 5 integer values.

Output

Print a message like the following example with all letters in lowercase, indicating how many of these values ​​areeven, odd, positive and negative.
Input SampleOutput Sample
-5
0
-3
-4
12
3 valor(es) par(es)
2 valor(es) impar(es)
1 valor(es) positivo(s)
3 valor(es) negativo(s)

Solution....

#include<stdio.h>
int main()
{
    int even=0,odd=0,positive=0,negetive=0,n=0,a;
    while(n!=5){
        scanf("%d",&a);
        if(a%2==0){
            even++;
        }
        if(a%2!=0){
            odd++;
        }
        if(a>0){
            positive++;
        }
        if(a<0){
            negetive++;
        }
        n++;
    }
    printf("%d valor(es) par(es)\n",even);
    printf("%d valor(es) impar(es)\n",odd);
    printf("%d valor(es) positivo(s)\n",positive);
    printf("%d valor(es) negativo(s)\n",negetive);
    return 0;
}

URI-1065

URI Online Judge | 1065

Even Between five Numbers

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Make a program that reads five integer valuesCount how many of these values ​​are even and  print this information like the following example.

Input

The input will be 5 integer values.

Output

Print a message like the following example with all letters in lowercase, indicating how many even numbers were typed.
Input SampleOutput Sample
7
-5
6
-4
12
3 valores pares


Solution...

#include<stdio.h>
int main()
{
    int count=0,n=0,a;
    while(n!=5){
        scanf("%d",&a);
        if(a%2==0){
            count++;
        }
        n++;
    }
    printf("%d valores pares\n",count);
    return 0;
}

URI-1064

URI Online Judge | 1064

Positives and Average

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read 6 values that can be floating point numbers. After, print how many of them were positive. In the next line, print the average of all positive values typed, with one digit after the decimal point.

Input

The input consist in 6 numbers that can be integer or floating point values. At least one number will be positive.

Output

The first output value is the amount of positive numbers. The next line should show the average of the positive values ​typed.
Input SampleOutput Sample
7
-5
6
-3.4
4.6
12
4 valores positivos
7.4


Solution....

#include<stdio.h>
int main()
{
    int count=0,n=0;
    float a,res,sum=0;
    while(n!=6){
        scanf("%f",&a);
        if(a>=0){
            count++;
            sum=sum+a;
        }
        n++;
    }
    res=sum/count;
    printf("%d valores positivos\n",count);
    printf("%.1f\n",res);
    return 0;
}

URI-1060

URI Online Judge | 1060

Positive Numbers

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Write a program that reads 6 numbers. These numbers will only be positive or negative (disregard null values). Print the total number of positive numbers.

Input

Six numbers, positive and/or negative.

Output

Print a message with the total number of positive numbers.
Input SampleOutput Sample
7
-5
6
-3.4
4.6
12
4 valores positivos

Solution...

#include<stdio.h>
int main()
{
    int count=0,n=0;
    float a;
    while(n!=6){
        scanf("%f",&a);
        if(a>=0){
            count++;
        }
        n++;
    }
    printf("%d valores positivos\n",count);
    return 0;
}

URI-1059

URI Online Judge | 1059

Even Numbers

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Write a program that prints all even numbers between 1 and 100, including them if it is the case.

Input

In this extremely simple problem there is no input.

Output

Print all even numbers between 1 and 100, including them, one by row.
Input SampleOutput Sample
2
4
6
...
100

Solution....

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

URI-1052

URI Online Judge | 1052

Month

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read an integer number between 1 and 12, including. Corresponding to this number, you must print the month of the year, in english, with the first letter in uppercase.

Input

The input contains only an integer number.

Output

Print the name of the month according to the input number, with the first letter in uppercase.
Input SampleOutput Sample
4April

Solution...

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    switch(n)
    {
    case 1:
        printf("January\n");
        break;
    case 2:
        printf("February\n");
        break;
    case 3:
        printf("March\n");
        break;
    case 4:
        printf("April\n");
        break;
    case 5:
        printf("May\n");
        break;
    case 6:
        printf("June\n");
        break;
    case 7:
        printf("July\n");
        break;
    case 8:
        printf("August\n");
        break;
    case 9:
        printf("September\n");
        break;
    case 10:
        printf("October\n");
        break;
    case 11:
        printf("November\n");
        break;
    case 12:
        printf("December\n");
    }
    return 0;
}


URI-1050

URI Online Judge | 1050

DDD

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read an integer number that is the code number for phone dialing. Then, print the destination according to the following table:

If the input number isn’t found in the above table, the output must be:
DDD não cadastrado
That means “DDD not found” in Portuguese language.

Input

The input consists in a unique integer number.

Output

Print the city name corresponding to the input DDD. Print DDD nao cadastrado if doesn't exist corresponding DDD to the typed number.
Input SampleOutput Sample
11Sao Paulo

Solution...

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    switch(n)
    {
    case 61:
        printf("Brasilia\n");
        break;
    case 71:
        printf("Salvador\n");
        break;
    case 11:
        printf("Sao Paulo\n");
        break;
    case 21:
        printf("Rio de Janeiro\n");
        break;
    case 32:
        printf("Juiz de Fora\n");
        break;
    case 19:
        printf("Campinas\n");
        break;
    case 27:
        printf("Vitoria\n");
        break;
    case 31:
        printf("Belo Horizonte\n");
        break;
    default :
        printf("DDD nao cadastrado\n");
        break;
    }
    return 0;
}

URI-1047

URI Online Judge | 1047

Game Time with Minutes

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read the start time and end time of a game, in hours and minutes (initial hour, initial minute, final hour, final minute). Then print the duration of the game, knowing that the game can begin in a day and finish in another day,
Obs.: With a maximum game time of 24 hours and the minimum game time of 1 minute.

Input

Four integer numbers representing the start and end time of the game.

Output

Print the duration of the game in hours and minutes, in this format: “O JOGO DUROU XXX HORA(S) E YYY MINUTO(S)” . Which means: the game lasted XXX hour(s) and YYY minutes.
Input SampleOutput Sample
7 8 9 10O JOGO DUROU 2 HORA(S) E 2 MINUTO(S)
7 7 7 7O JOGO DUROU 24 HORA(S) E 0 MINUTO(S)
7 10 8 9O JOGO DUROU 0 HORA(S) E 59 MINUTO(S)

Solution...

#include <stdio.h>

int main()
{
    int st, sm, et, em, rm, rt;
    scanf("%d %d %d %d", &st, &sm, &et, &em);
    rt = et - st;
    if (rt < 0){
        rt = 24 + (et - st);
    }
    rm = em - sm;
    if (rm < 0){
        rm = 60 + (em - sm);
        rt--;
    }
    if (et == st && em == sm){
        printf("O JOGO DUROU 24 HORA(S) E 0 MINUTO(S)\n");
    }
    else
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", rt, rm);
    return 0;
}

URI-1046

URI Online Judge | 1046

Game Time

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read the start time and end time of a game, in hours. Then calculate the duration of the game, knowing that the game can begin in a day and finish in another day, with a maximum duration of 24 hours. The message must be printed in portuguese “O JOGO DUROU X HORA(S)” that means “THE GAME LASTED X HOUR(S)”

Input

Two integer numbers representing the start and end time of a game.

Output

Print the duration of the game as in the sample output.
Input SampleOutput Sample
16 2O JOGO DUROU 10 HORA(S)
0 0O JOGO DUROU 24 HORA(S)
2 16O JOGO DUROU 14 HORA(S)

Solution...

#include <stdio.h>

int main()
{
    int st, et, rt;
    scanf("%d %d", &st, &et);
    rt = et - st;
    if (rt < 0){
        rt = 24 + (et - st);
    }
    if (st == et){
        printf("O JOGO DUROU 24 HORA(S)\n");
    }
    else{
        printf("O JOGO DUROU %d HORA(S)\n", rt);
    }
    return 0;
}

URI-1045

URI Online Judge | 1045

Triangle Types

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read 3 double numbers (A, B and C) representing the sides of a triangle and arrange them in decreasing order, so that the side A is the biggest of the three sides. Next, determine the type of triangle that they can make, based on the following cases always writing an appropriate message:
  • if A ≥ B + C, write the message: NAO FORMA TRIANGULO
  • if A2 = B2 + C2, write the message: TRIANGULO RETANGULO
  • if A2 > B2 + C2, write the message: TRIANGULO OBTUSANGULO
  • if A2 < B2 + C2, write the message: TRIANGULO ACUTANGULO
  • if the three sides are the same size, write the message: TRIANGULO EQUILATERO
  • if only two sides are the same and the third one is different, write the message: TRIANGULO ISOSCELES

Input

The input contains three double numbers, A (0 < A) , B (0 < B) and C (0 < C).

Output

Print all the classifications of the triangle presented in the input.
Input SamplesOutput Samples
7.0 5.0 7.0TRIANGULO ACUTANGULO
TRIANGULO ISOSCELES
6.0 6.0 10.0TRIANGULO OBTUSANGULO
TRIANGULO ISOSCELES
6.0 6.0 6.0TRIANGULO ACUTANGULO
TRIANGULO EQUILATERO
5.0 7.0 2.0NAO FORMA TRIANGULO
6.0 8.0 10.0TRIANGULO RETANGULO


Solution...

#include <stdio.h>

int main()
{
    double a, b, c, temp;
    scanf("%lf %lf %lf", &a, &b, &c);
    if (a < b){
        temp = a;
        a = b;
        b = temp;
    }
    if (b < c){
        temp = b;
        b = c;
        c = temp;
    }
    if (a < b){
        temp = a;
        a = b;
        b = temp;
    }
    if (a >= b + c){
        printf("NAO FORMA TRIANGULO\n");
    }
    else if (a * a == b * b + c * c){
        printf("TRIANGULO RETANGULO\n");
    }
    else if (a * a > b * b + c * c){
    printf("TRIANGULO OBTUSANGULO\n");
    }
    else if (a * a < b * b + c * c){
        printf("TRIANGULO ACUTANGULO\n");
    }
    if (a == b && b == c){
        printf("TRIANGULO EQUILATERO\n");
    }
    else if (a == b || b == c){
        printf("TRIANGULO ISOSCELES\n");
    }
    return 0;
}

URI-1044

URI Online Judge | 1044

Multiples

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read two nteger values (A and B). After, the program should print the message "Sao Multiplos" (are multiples) or "Nao sao Multiplos" (aren’t multiples), corresponding to the read values.

Input

The input has two integer numbers.

Output

Print the relative message to the input as stated above.
Input SampleOutput Sample
6 24Sao Multiplos
6 25Nao sao Multiplos


Solution...

#include <stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if ( a%b==0||b%a==0){
        printf("Sao Multiplos\n");
    }
    else{
        printf("Nao sao Multiplos\n");
    }
    return 0;
}

Sunday 13 November 2016

URI-1043

URI Online Judge | 1043

Triangle

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read three point floating values (A, B and C) and verify if is possible to make a triangle with them. If it is possible, calculate the perimeter of the triangle and print the message:

Perimetro = XX.X

If it is not possible, calculate the area of the trapezium which basis A and B and C as height, and print the message:

Area = XX.X

Input

The input file has tree floating point numbers.

Output

Print the result with one digit after the decimal point.
Input SampleOutput Sample
6.0 4.0 2.0Area = 10.0
6.0 4.0 2.1Perimetro = 12.1


Solutin...

#include <stdio.h>
int main()
{
    double a,b,c;
    scanf("%lf %lf %lf",&a,&b,&c);
    if (a < b + c && b < a + c && c < a + b){
        printf("Perimetro = %.1f\n", a + b + c);
    }
    else{
        printf("Area = %.1f\n", c * (a + b) / 2);
    }
    return 0;
}


URI-1042

URI Online Judge | 1042

Simple Sort

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read three integers and sort them in ascending order. After, print these values in ascending order, a blank line and then the values in the sequence as they were readed.

Input

The input contains three integer numbers.

Output

Present the output as requested above.
Input SampleOutput Sample
7 21 -14-14
7
21

7
21
-14
-14 21 7-14
7
21

-14
21
7


Solution...


#include <stdio.h>
int main()
{
    int a, b, c, g, m, s, temp;
    scanf("%d %d %d", &a, &b, &c);
    g = a;
    m = b;
    s = c;
    if (g < m){
        temp = g;
        g = m;
        m = temp;
    }
    if (m < s){
        temp = m;
        m = s;
        s = temp;
    }
    if (g < m){
        temp = g;
        g = m;
        m = temp;
    }
    printf("%d\n%d\n%d\n\n%d\n%d\n%d\n",s,m,g,a,b,c);
    return 0;
}


URI-1041

URI Online Judge | 1041

Coordinates of a Point

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Write an algorithm that reads two floating values (x and y), which should represent the coordinates of a point in a plane. Next, determine which quadrant the point belongs, or if you are over one of the Cartesian axes or the origin (x = y = 0).
If the point is at the origin, write the message "Origem".
If the point is over X axis write "Eixo X", else if the point is over Y axis write "Eixo Y".

Input

The input contains the coordinates of a point.

Output

The output should display the quadrant in which the point is.
Input SampleOutput Sample
4.5 -2.2Q4
0.1 0.1Q1
0.0 0.0Origem

Solutin...

#include <stdio.h>
int main()
{
    double x, y;
    scanf("%lf %lf", &x, &y);
    if (x == 0.0 && y == 0.0){
        printf("Origem\n");
    }
    else if (x == 0.0 && y != 0.0){
        printf("Eixo Y\n");
    }
    else if (y == 0.0 && x != 0.0){
        printf("Eixo X\n");
    }
    else if (x > 0.0){
        if (y > 0.0){
            printf("Q1\n");
        }
        else printf("Q4\n");
    }
    else if (y > 0.0){
        printf("Q2\n");
    }
    else printf("Q3\n");
    return 0;
}



URI-1038

URI Online Judge | 1038

Snack

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Using the following table, write a program that reads a code and the amount of an item. After, print the value to pay. This is a very simple program with the only intention of practice of selection commands.

Input

The input file contains two integer numbers and Yis the product code and is the quantity of this item according to the above table.

Output

The output must be a message "Total: R$ " followed by the total value to be paid, with 2 digits after the decimal point.
Input SampleOutput Sample
3 2Total: R$ 10.00
4 3Total: R$ 6.00
2 3Total: R$ 13.50

Solution...

#include<stdio.h>
int main()
{
    float a=4.00,b=4.50,c=5.00,d=2.00,e=1.50;
    int m,n;
    scanf("%d%d",&m,&n);
    if(m==1){printf("Total: R$ %.2f\n",a*n);}
    else if(m==2){printf("Total: R$ %.2f\n",b*n);}
    else if(m==3){printf("Total: R$ %.2f\n",c*n);}
    else if(m==4){printf("Total: R$ %.2f\n",d*n);}
    else if(m==5){printf("Total: R$ %.2f\n",e*n);}
    return 0;
}