Posts

Showing posts from August, 2017

URI ONLINE JUDGE SOLUTION 1044 - Multiples

Image
Problem 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. Solution C programming source code for uri online judge beginner problem 1044-Multiples: #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; } How it works? This is the beginner level  problem of uri online judge.Here you would have to check if one the number is dividable by other one.If it is then you should print the first message if not then you should print the second message.Hopefully you would understand the problem.Don't copy paste the code as s

URI ONLINE JUDGE SOLUTION 1043 - Triangle

Image
Problem 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. Solution C programming source code for uri online judge beginner problem 1043 - Triangle: #include<stdio.h> int main() {     double a,b,c;     scanf("%lf%lf%lf",&a,&b,&c);     if(a+b>c && b+c>a && c+a>b)         printf("Perimetro = %0.1lf\n",a+b+c);     else         printf("Area = %0.1lf\n",0.5*(a+b)*c);     return 0; } How it works? This is the beginner level  problem of uri online judge.Here you would have to check if it i

URI ONLINE JUDGE SOLUTION 1042 - Simple Sort

Image
Problem 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. Solution C programming source code for uri online judge beginner problem  1042 - Simple Sort #include<stdio.h> int main() {     int val[3],sort[3],i,j,temp;     for(i=0;i<3;i++){         scanf("%d",&val[i]);         sort[i]=val[i];}     for(i=0;i<2;i++){         for(j=0;j<2;j++){         if(sort[j]>sort[j+1]){          temp=sort[j+1];          sort[j+1]=sort[j];          sort[j]=temp;}            }     }     for(i=0;i<3;i++)     printf("%d\n",sort[i]);     printf("\n");     for(i=0;i<3;i++)     printf("%d\n",val[i]);     return 0; } How it works? This is the beginner level problem of uri online judge.Here y

URI ONLINE JUDGE SOLUTION 1041 - Coordinates of a Point

Image
Problem 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. Solution #include<stdio.h> int main() {     double x,y;     scanf("%lf%lf",&x,&y);     if(x == 0 & y == 0)         printf("Origem\n");     if(y == 0 && x!=0)         printf("Eixo X\n");     if(x == 0 && y!=0)         printf("Eixo Y\n");     if(x > 0 && y > 0)         printf("Q1\n");     if(x < 0

URI ONLINE JUDGE SOLUTION 1040 - Average 3

Image
Problem Read four numbers (N 1 , N 2 , N 3 , N 4 ), 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

URI ONLINE JUDGE SOLUTION 1038 - Snack

Image
Problem 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 X and Y . X is the product code and Y 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. Solution #include<stdio.h> int main() {     int x,y;     double total = 0.0;     scanf("%d%d",&x,&y);     if(x == 1){         total = y*4.0;     }     if(x == 2){         total = y*4.5;     }     if(x == 3){         total = y*5.0;     }     if(x == 4){         total = y*2.0;     }     if(x == 5){         total = y*1.5;     }     printf("Total: R$ %0.2lf\n",total);     return 0; } Solution Tricks:Suppose,There are

URI ONLINE JUDGE SOLUTION 1037 - Interval

Image
Problem You must make a program that read a float-point number and print a message saying in which of following intervals the number belongs: [0,25] (25,50], (50,75], (75,100]. If the read number is less than zero or greather than 100, the program must print the message “Fora de intervalo” that means "Out of Interval". The symbol '(' represents greather than. For example: [0,25] indicates numbers between 0 and 25.0000, including both. (25,50] indicates numbers greather than 25 (25.00001) up to 50.0000000. Input The input file contains a floating-point number. Output The output must be a message like following example. Solution #include<stdio.h> int main() {     double x;     scanf("%lf",&x);     if(x >= 0 &&

URI ONLINE JUDGE SOLUTION 1036 - Bhaskara's Formula

Image
Problem Read 3 floating-point numbers. After, print the roots of bhaskara’s formula. If it's impossible to calculate the roots because a division by zero or a square root of a negative number, presents the message “Impossivel calcular” . Input Read 3 floating-point numbers A, B and C. Output Print the result with 5 digits after the decimal point or the message if it is impossible to calculate. Solution #include<stdio.h> #include<math.h> int main() {     double A,B,C,d,r1,r2;     scanf("%lf%lf%lf",&A,&B,&C);     d = B*B-4*A*C;     if(A != 0 && d>=0)     {         d = sqrt(d);         r1 = (d-B)/(2*A);         r2 = (-d-B)/(2*A);         printf("R1 = %0.5lf\nR2 = %0.5lf\n",r1,r2);     }     else printf("Impossivel calcular\n");     return 0; } Description: Here the problem is about a mathematical equation. We already know a equation ax^2 + bx + c=0 .You have to find the roots of

URI ONLINE JUDGE SOLUTION 1035 - Selection Test 1

Image
Problem Read 4 integer values A, B, C and D. Then if B is greater than C and D is greater than A and if the sum of C and D is greater than the sum of A and B and if C and D were positives values and if A is even, write the message “Valores aceitos” (Accepted values). Otherwise, write the message “Valores nao aceitos” (Values not accepted). Input Four integer numbers A, B, C and D. Output Show the corresponding message after the validation of the values​​. Solution #include<stdio.h> int main() {     int A,B,C,D;     scanf("%d%d%d%d",&A,&B,&C,&D);     if(B>C && D>A && (C+D)>(A+B) && C>0 && D>0 && (A%2 == 0))         printf("Valores aceitos\n");     else         printf("Valores nao aceitos\n");     return 0; }

URI ONLINE JUDGE SOLUTION 1021 - Banknotes and Coins

Image
Problem Read a value of floating point with two decimal places. This represents a monetary value. After this, calculate the smallest possible number of notes and coins on which the value can be decomposed. The considered notes are of 100, 50, 20, 10, 5, 2. The possible coins are of 1, 0.50, 0.25, 0.10, 0.05 and 0.01. Print the message “NOTAS:” followed by the list of notes and the message “MOEDAS:” followed by the list of coins. Input The input file contains a value of floating point N (0 ≤ N ≤ 1000000.00). Output Print the minimum quantity of banknotes and coins necessary to change the initial value, as the given example. Solution #include<stdio.h> int main() {     int c[12],n,f,i,num[] = {100,50,20,10,5,2,100,50,25,10,5,1};     double x;     scanf("%lf",&x);     n = x;     f = x*100;     f = f%100;     printf("NOTAS:\n&q

URI ONLINE JUDGE SOLUTION 1020 - Age in Days

Image
Problem Read an integer value corresponding to a person's age (in days) and print it in years, months and days, followed by its respective message “ano(s)”, “mes(es)”, “dia(s)”. Note: only to facilitate the calculation, consider the whole year with 365 days and 30 days every month. In the cases of test there will never a situation that allows 12 months and some days, like 360, 363 or 364. This is just an exercise for the purpose of testing simple mathematical reasoning. Input The input file contains 1 integer value. Output Print the output, like the following example. Solution #include<stdio.h> int main() {     int x,a[3];     scanf("%d",&x);     a[0]=x/365;     x=x%365;     a[1]=x/30;     a[2]=x%30;     printf("%d ano(s)\n%d mes(es)\n%d dia(s)\n",a[0],a[1],a[2]);     return 0; }

URI ONLINE JUDGE SOLUTION 1019 - Time Conversion

Image
Problem Read an integer value, which is the duration in seconds of a certain event in a factory, and inform it expressed in hours:minutes:seconds. Input The input file contains an integer N . Output Print the read time in the input file (seconds) converted in hours:minutes:seconds like the following example. Solution #include<stdio.h> int main() {     int N, a[3];     scanf("%d", &N);     a[0] = N/3600;     N = N%3600;     a[1] = N/60;     a[2] = N%60;     printf("%d:%d:%d\n", a[0], a[1], a[2]);     return 0; }

URI ONLINE JUDGE SOLUTION 1018 - Banknotes

Image
Problem In this problem you have to read an integer value and calculate the smallest possible number of banknotes in which the value may be decomposed. The possible banknotes are 100, 50, 20, 10, 5, 2 e 1. Print the read value and the list of banknotes. Input The input file contains an integer value N (0 < N < 1000000). Output Print the read number and the minimum quantity of each necessary banknotes in Portuguese language, as the given example. Do not forget to print the end of line after each line, otherwise you will receive “Presentation Error” . Solution #include<stdio.h> int main() {     int x,i,n[]={100,50,20,10,5,2,1},y[7];     scanf("%d",&x);     printf("%d\n",x);     for(i=0;i<7;i++){         y[i]=x/n[i];         x=x%n[i];         printf("%d nota(s) de R$ %d,00\n",y[i],n[i]);

URI ONLINE JUDGE SOLUTION 1017 - Fuel Spent

Image
Problem Little John wants to calculate and show the amount of spent fuel liters on a trip, using a car that does 12 Km/L. For this, he would like you to help him through a simple program. To perform the calculation, you have to read spent time (in hours) and the same average speed (km/h). In this way, you can get distance and then, calculate how many liters would be needed. Show the value with three decimal places after the point. Input The input file contains two integers. The first one is the spent time in the trip (in hours). The second one is the average speed during the trip (in Km/h). Output Print how many liters would be needed to do this trip, with three digits after the decimal point. Solution #include<stdio.h> int main() {     int time,speed;     double fuel;     scanf("%d%d",&time,&speed);     fuel=(time*speed)/12.0;

URI ONLINE JUDGE SOLUTION 1016 - Distance

Image
Problem Two cars (X and Y) leave in the same direction. The car X leaves with a constant speed of 60 km/h and the car Y leaves with a constant speed of 90 km / h. In one hour (60 minutes) the car Y can get a distance of 30 kilometers from the X car, in other words, it can get away one kilometer for each 2 minutes. Read the distance (in km) and calculate how long it takes (in minutes) for the car Y to take this distance in relation to the other car. Input The input file contains 1 integer value. Output Print the necessary time followed by the message " minutos" that means minutes in Portuguese. Solution #include<stdio.h> int main() {     int x;     scanf("%d",&x);     printf("%d minutos\n",x*2);     return 0; }

URI ONLINE JUDGE SOLUTION 1015 - Distance Between Two Points

Image
Problem: Read the four values corresponding to the x and y axes of two points in the plane, p1 (x1, y1) and p2 (x2, y2) and calculate the distance between them, showing four decimal places after the comma, according to the formula: Distance = Input The input file contains two lines of data. The first one contains two double values:  x1 y1 and the second one also contains two double values with one digit after the decimal point: x2 y2 . Output Calculate and print the distance value using the provided formula, with 4 digits after the decimal point. Solution: #include<stdio.h> #include<math.h> int main() {     double x1,x2,y1,y2,dis;     scanf("%lf%lf%lf%lf",&x1,&x2,&y1,&y2);     dis=sqrt(pow((y1-x1),2)+pow((y2-x2),2));     printf("%0.4lf\n",dis);     return 0; }

URI ONLINE JUDGE SOLUTION 1014 - Consumption

Image
Problem: Calculate a car's average consumption being provided the total distance traveled (in Km) and the spent fuel total (in liters). Input The input file contains two values: one integer value X representing the total distance (in Km) and the second one is a floating point number Y  representing the spent fuel total, with a digit after the decimal point. Output Present a value that represents the average consumption of a car with 3 digits after the decimal point, followed by the message "km/l". Solution: #include<stdio.h> int main() {     int X;     double Y,con;     scanf("%d%lf",&X,&Y);     con=(X/Y);     printf("%0.3lf km/l\n",con);     return 0; }

URI ONLINE JUDGE SOLUTION 1013 - The Greatest

Image
Problem: Make a program that reads 3 integer values and present the greatest one followed by the message "eh o maior". Use the following formula: Input The input file contains 3 integer values. Output Print the greatest of these three values followed by a space and the message “eh o maior”. Solution: #include <stdio.h> #include<math.h> int main() {     int a,b,c,ans,great;     scanf("%d%d%d",&a,&b,&c);     ans=(a+b+abs(a-b))/2;     great=(c+ans+abs(c-ans))/2;     printf("%d eh o maior\n",great);     return 0; }

URI ONLINE JUDGE SOLUTION 1012 - Area

Image
Problem: Make a program that reads three floating point values: A, B and C. Then, calculate and show: a) the area of the rectangled triangle that has base A and height C. b) the area of the radius's circle C. (pi = 3.14159) c) the area of the trapezium which has A and B by base, and C by height. d) the area of ​​the square that has side B. e) the area of the rectangle that has sides A and B. Input The input file contains three double values with one digit after the decimal point. Output The output file must contain 5 lines of data. Each line corresponds to one of the areas described above, always with a corresponding message (in Portuguese) and one space between the two points and the value. The value calculated must be presented with 3 digits after the decimal point. Solution: #include<stdio.h> #define pi 3.14159

URI ONLINE JUDGE SOLUTION 1011 - Sphere

Image
Problem: Make a program that calculates and shows the volume of a sphere being provided the value of its radius (R) . The formula to calculate the volume is: (4/3) * pi * R 3 . Consider (assign) for pi the value 3.14159. Tip: Use (4/3.0) or (4.0/3) in your formula, because some languages (including C++) assume that the division's result between two integers is another integer. :) Input The input contains a value of floating point (double precision). Output The output must be a message "VOLUME" like the following example with a space before and after the equal signal. The value must be presented with 3 digits after the decimal point. Solution: #include<stdio.h> #define pi 3.14159 int main() {     double R,a;     scanf("%lf",&R);     a=(4.0/3)*pi*R*R*R;     printf("VOLUME = %0.3lf\n",a);     return 0; }

URI ONLINE JUDGE SOLUTION 1010 - Simple Calculate

Image
Problem: In this problem, the task is to read a code of a product 1, the number of units of product 1, the price for one unit of product 1, the code of a product 2, the number of units of product 2 and the price for one unit of product 2. After this, calculate and show the amount to be paid. Input The input file contains two lines of data. In each line there will be 3 values: two integers and a floating value with 2 digits after the decimal point. Output The output file must be a message like the following example where "Valor a pagar" means Value to Pay . Remember the space after ":" and after "R$" symbol. The value must be presented with 2 digits after the point. Solution: #include<stdio.h> int main() {     int a[4];     double b[2],paid;     scanf("%d%d%lf",&a[0],&a[1],&b[0]);     scanf("%d%d%lf",&a[2],&a[3],&b[1]);     paid=a[1]*b[0]+a[3]*b[1];     printf("VALOR A

URI ONLINE JUDGE SOLUTION - 1009 Salary with Bonus

Image
Problem: Make a program that reads a seller's name, his/her fixed salary and the sale's total made by himself/herself in the month (in money). Considering that this seller receives 15% over all products sold, write the final salary (total) of this seller at the end of the month , with two decimal places. - Don’t forget to print the line's end after the result, otherwise you will receive “ Presentation Error ”. - Don’t forget the blank spaces. Input The input file contains a text (employee's first name), and two double precision values, that are the seller's salary and the total value sold by him/her. Output Print the seller's total salary, according to the given example. Solution: #include<stdio.h> int main() {     char name[50];     double a,b,total;     gets(name);     scanf("%lf%lf",&a,&b);     total=b*0.15+a;     printf("TOTAL = R$ %0.2lf\n",total);     return 0; }

URI ONLINE JUDGE SOLUTION - 1008 Salary

Image
Problem: Write a program that reads an employee's number, his/her worked hours number in a month and the amount he received per hour. Print the employee's number and salary that he/she will receive at end of the month, with two decimal places. Don’t forget to print the line's end after the result, otherwise you will receive “Presentation Error”. Don’t forget the space before and after the equal signal and after the U$. Input The input file contains 2 integer numbers and 1 value of floating point, representing the number, worked hours amount and the amount the employee receives per worked hour. Output Print the number and the employee's salary, according to the given example, with a blank space before and after the equal signal.                  Solution: #include<stdio.h> int main() {     int a,b;     double c,s;     scanf("%d%d%lf",&a,&b,&c);     s=b*c;     printf("

URI ONLINE JUDGE SOLUTION 1007 - Difference

Image
Problem: Read four integer values named A, B, C and D. Calculate and print the difference of product A and B by the product of C and D (A * B - C * D). Input The input file contains 4 integer values. Output Print DIFERENCA (DIFFERENCE in Portuguese) with all the capital letters, according to the following example, with a blank space before and after the equal signal. Solution: #include<stdio.h> int main() {     int A,B,C,D,diff;     scanf("%d%d%d%d",&A,&B,&C,&D);     diff=(A*B)-(C*D);     printf("DIFERENCA = %d\n",diff);     return 0; }

URI ONLINE JUDGE SOLUTION 1006 - Average 2

Image
Problem: Read three values (variables A, B and C), which are the three student's grades. Then, calculate the average, considering that grade A has weight 2, grade B has weight 3 and the grade C has weight 5. Consider that each grade can go from 0 to 10.0, always with one decimal place. Input The input file contains 3 values of floating points with one digit after the decimal point. Output Print MEDIA (average in Portuguese) according to the following example, with a blank space before and after the equal signal. Solution: #include<stdio.h> int main() {     double A,B,C,MEDIA;     scanf("%lf",&A);     scanf("%lf",&B);     scanf("%lf",&C);     MEDIA=((A*2)+(B*3)+(C*5))/10;     printf("MEDIA = %0.1lf\n",MEDIA);     return 0; }

URI ONLINE JUDGE SOLUTION 1005 - Average 1

Image
Problem: Read two floating points' values of double precision A and B, corresponding to two student's grades. After this, calculate the student's average, considering that grade A has weight 3.5 and B has weight 7.5. Each grade can be from zero to ten, always with one digit after the decimal point. Don’t forget to print the end of line after the result, otherwise you will receive “Presentation Error” . Don’t forget the space before and after the equal sign. Input The input file contains 2 floating points' values with one digit after the decimal point. Output Print MEDIA (average in Portuguese) according to the following example, with 5 digits after the decimal point and with a blank space before and after the equal signal. Solution: #include<stdio.h> int main() {     double A,B,MEDIA;     scanf("%lf",&A);     scanf("%lf",&B);     MEDIA=((A*3.5)+(B*7.5))/(3.5+7.5);     printf("MEDIA = %0.5lf\n"

URI ONLINE JUDGE SOLUTION 1004 - Simple Product

Image
Problem: Read two integer values. After this, calculate the product between them and store the result in a variable named PROD . Print the result like the example below. Do not forget to print the end of line after the result, otherwise you will receive “Presentation Error” . Input The input file contains 2 integer numbers. Output Print PROD according to the following example, with a blank space before and after the equal signal. Solution: #include<stdio.h> int main() {     int A,B,PROD;     scanf("%d",&A);     scanf("%d",&B);     PROD=A*B;     printf("PROD = %d\n",PROD);     return 0; }

URI ONLINE JUDGE SOLUTION 1003 - Simple Sum

Image
Problem: Read two integer values, in this case, the variables A and B. After this, calculate the sum between them and assign it to the variable SOMA . Write the value of this variable. Input The input file contains 2 integer numbers. Output Print the variable SOMA with all the capital letters, with a blank space before and after the equal signal followed by the corresponding value to the sum of A and B. Like all the problems, don't forget to print the end of line, otherwise you will receive "Presentation Error" Solution: #include<stdio.h> int main() {     int A,B,SOMA;     scanf("%d",&A);     scanf("%d",&B);     SOMA=A+B;     printf("SOMA = %d\n",SOMA);     return 0; }

URI ONLINE JUDGE SOLUTION 1002 - Area of a Circle

Image
Problem: The formula to calculate the area of a circumference is defined as A = π . R 2 . Considering to this problem that π = 3.14159 : Calculate the area using the formula given in the problem description. Input The input contains a value of floating point (double precision), that is the variable R . Output Present the message "A=" followed by the value of the variable, as in the example bellow, with four places after the decimal point. Use all double precision variables. Like all the problems, don't forget to print the end of line after the result, otherwise you will receive "Presentation Error". Solution: #include<stdio.h> #define pi 3.14159 int main() {     double R,A;     scanf("%lf",&R);     A=pi*R*R;     printf("A=%0.4lf\n",A);     return 0; }

URI ONLINE JUDGE SOLUTION 1001 - Extremely Basic

Image
Problem: Read 2 integer values and store them in variables, named A and B and make the sum of these two variables, assigning its result to the variable X . Print X as shown below. Don't present any message beyond what is being specified and don't forget to print the end of line after the result, otherwise you will receive “ Presentation Error ”. Input The input file contain 2 integer values. Output Print the variable X according to the following example, with a blank space before and after the equal signal. 'X' is uppercase and you have to print a blank space before and after the '=' signal.              Solution: #include<stdio.h> int main() {     int A,B,X;     scanf("%d",&A);     scanf("%d",&B);     X=A+B;     printf("X = %d\n",X);     return 0; }