Beecrowd Problem 1021-1040 Solve by C
Beecrowd Problem 1021
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.
Input Sample | Output Sample |
576.73 | NOTAS: 5 nota(s) de R$ 100.00 1 nota(s) de R$ 50.00 1 nota(s) de R$ 20.00 0 nota(s) de R$ 10.00 1 nota(s) de R$ 5.00 0 nota(s) de R$ 2.00 MOEDAS: 1 moeda(s) de R$ 1.00 1 moeda(s) de R$ 0.50 0 moeda(s) de R$ 0.25 2 moeda(s) de R$ 0.10 0 moeda(s) de R$ 0.05 3 moeda(s) de R$ 0.01 |
4.00 | NOTAS: 0 nota(s) de R$ 100.00 0 nota(s) de R$ 50.00 0 nota(s) de R$ 20.00 0 nota(s) de R$ 10.00 0 nota(s) de R$ 5.00 2 nota(s) de R$ 2.00 MOEDAS: 0 moeda(s) de R$ 1.00 0 moeda(s) de R$ 0.50 0 moeda(s) de R$ 0.25 0 moeda(s) de R$ 0.10 0 moeda(s) de R$ 0.05 0 moeda(s) de R$ 0.01 |
91.01 | NOTAS: 0 nota(s) de R$ 100.00 1 nota(s) de R$ 50.00 2 nota(s) de R$ 20.00 0 nota(s) de R$ 10.00 0 nota(s) de R$ 5.00 0 nota(s) de R$ 2.00 MOEDAS: 1 moeda(s) de R$ 1.00 0 moeda(s) de R$ 0.50 0 moeda(s) de R$ 0.25 0 moeda(s) de R$ 0.10 0 moeda(s) de R$ 0.05 1 moeda(s) de R$ 0.01 |
#include <stdio.h> int main() { double n, d[] = {100.0, 50.0, 20.0, 10.0, 5.0, 2.0, 1.0, 0.5, 0.25, 0.10, 0.05, 0.01}; int t = 0, c; scanf("%lf", &n); printf("NOTAS:\n"); t = 0; n+=1e-9; while (d[t] >= 0.01) { c = 0; while (n >= d[t]) { n -= d[t]; c++; } if (d[t] == 1.0) printf("MOEDAS:\n"); if (d[t] >= 2.0 ) printf("%d nota(s) de R$ %.2f\n", c, d[t]); else printf("%d moeda(s) de R$ %.2f\n", c, d[t]); t++; } return 0; }
Beecrowd Problem 1022
You were invited to do a little job for your Mathematic teacher. The job is to read a Mathematic expression in format of two rational numbers (numerator / denominator) and present the result of the operation. Each operand or operator is separated by a blank space. The input sequence (each line) must respect the following format: number, (‘/’ char), number, operation char (‘/’, ‘*’, ‘+’, ‘-‘), number, (‘/’ char), number. The answer must be presented followed by ‘=’ operator and the simplified answer. If the answer can’t be simplified, it must be repeated after a ‘=’ operator.
Considering N1 and D1 as numerator and denominator of the first fraction, follow the orientation about how to do each one of these 4 operations:
Sum: (N1*D2 + N2*D1) / (D1*D2)
Subtraction: (N1*D2 – N2*D1) / (D1*D2)
Multiplication: (N1*N2) / (D1*D2)
Division: (N1/D1) / (N2/D2), that means (N1*D2)/(N2*D1)
Input
The input contains several cases of test. The first value is an integer N (1 ≤ N ≤ 1*104), indicating the amount of cases of test that must be read. Each case of test contains a rational value X (1 ≤ X ≤ 1000), an operation (-, +, * or /) and another rational value Y (1 ≤ Y ≤ 1000).
Output
The output must be a rational number, followed by a “=“ sign and another rational number, that is the simplification of the first value. In case of the first value can’t be simplified, the same value must be repeated after the ‘=’ sign.
Input Sample | Output Sample |
4 1 / 2 + 3 / 4 1 / 2 – 3 / 4 2 / 3 * 6 / 6 1 / 2 / 3 / 4 |
10/8 = 5/4 -2/8 = -1/4 12/18 = 2/3 4/6 = 2/3 |
#include <stdio.h> int euclides(int a, int b) { int divisor, dividendo, c; if (a == 0) return 1; if (b > a) { dividendo = b; divisor = a; } else { dividendo = a; divisor = b; } while (dividendo % divisor != 0) { c = dividendo % divisor; dividendo = divisor; divisor = c; } return divisor; } int main() { char c1, c2, c3; int n, N1, N2, D1, D2, num, den, numS, denS, e; scanf("%i", &n); int i; for (i = 0; i < n; ++i) { scanf("%i %c %i %c %i %c %i", &N1, &c1, &D1, &c2, &N2, &c3, &D2); if (c2 == '+') { num = ((N1 * D2) + (N2 * D1)); den = (D1 * D2); } else if (c2 == '-') { num = ((N1 * D2) - (N2 * D1)); den = (D1 * D2); } else if (c2 == '*') { num = (N1 * N2); den = (D1 * D2); } else { num = (N1 * D2); den = (N2 * D1); } e = euclides(num, den); numS = num / e; denS = den / e; if (numS > 0 && denS > 0) { printf("%i/%i = %i/%i\n", num, den, numS, denS); } else { if (denS < 0) { denS = -denS; numS = -numS; } printf("%i/%i = %i/%i\n", num, den, numS, denS); }} return 0; }
Beecrowd Problem 1023
Due to the continuous drought that happened recently in some regions of Brazil, the Federal Government created an agency to assess the consumption of these regions in order to verify the behavior of the population at the time of rationing. This agency will take some cities (for sampling) and it will verify the consumption of each of the townspeople and the average consumption per inhabitant of each town.
Input
The input contains a number of test’s cases. The first line of each case of test contains an integer N (1 ≤ N ≤ 1 * 10 6), indicating the amount of properties. The following N lines contains a pair of values X (1 ≤ X ≤ 10) and Y ( 1 ≤ Y ≤ 200) indicating the number of residents of each property and its total consumption (m3). Surely, no residence consumes more than 200 m3 per month. The input’s end is represented by zero.
Output
For each case of test you must present the message “Cidade# n:”, where n is the number of the city in the sequence (1, 2, 3, …), and then you must list in ascending order of consumption, the people’s amount followed by a hyphen and the consumption of these people, rounding the value down. In the third line of output you should present the consumption per person in that town, with two decimal places without rounding, considering the total real consumption. Print a blank line between two consecutives test’s cases. There is no blank line at the end of output.
Input Sample | Output Sample |
3 3 22 2 11 3 39 5 1 25 2 20 3 31 2 40 6 70 2 1 1 3 2 0 |
Cidade# 1: 2-5 3-7 3-13 Consumo medio: 9.00 m3.Cidade# 2: 5-10 6-11 2-20 1-25 Consumo medio: 13.28 m3.Cidade# 3: 3-0 1-1 Consumo medio: 0.75 m3. |
#include <stdio.h> #include <stdlib.h> #include <map> #include <math.h> int main(){ int n, x, y, totalx, totaly, count; count = 0; while(1){ scanf("%dn", &n); if(n == 0) break; if(count != 0) printf("n"); totalx = totaly = 0; std::map<int,int> Resident; for(int i = 0; i < n; i++){ scanf("%d %dn", &x, &y); totalx += x; totaly += y; std::pair<std::map<int,int>::iterator,bool> ret; ret = Resident.insert(std::pair<int,int>(y/x,x)); if (ret.second==false){ Resident[y/x] += x; } } count++; printf("Cidade# %d:n", count); std::map<int,int>::const_iterator final_iter = Resident.end(); --final_iter; for(std::map<int,int>::const_iterator it = Resident.begin(); it != Resident.end(); ++it){ if(it == final_iter) printf("%d-%dn", it->second, it->first); else printf("%d-%d ", it->second, it->first); } printf("Consumo medio: %.2f m3.n", floor(100 * (float)totaly/totalx) / 100); } return 0; }
Beecrowd Problem 1024
You have been asked to build a simple encryption program. This program should be able to send coded messages without someone been able to read them. The process is very simple. It is divided into two parts.
First, each uppercase or lowercase letter must be shifted three positions to the right, according to the ASCII table: letter ‘a’ should become letter ‘d’, letter ‘y’ must become the character ‘|’ and so on. Second, each line must be reversed. After being reversed, all characters from the half on (truncated) must be moved one position to the left in ASCII. In this case, ‘b’ becomes ‘a’ and ‘a’ becomes ‘`’.
For example, if the resulting word of the first part is “tesla”, the letters “sla” should be moved one position to the left. However, if the resulting word of the first part is “t#$A”, the letters “$A” are to be displaced.
Input
The input contains a number of cases of test. The first line of each case of test contains an integer N (1 ≤ N ≤ 1 * 10⁴), indicating the number of lines the problem should encrypt. The following N lines contain M characters each M (1 ≤ M ≤ 1 * 10³).
Output
For each input, you must present the encrypted message.
Input Sample | Output Sample |
4 Texto #3 abcABC1 vxpdylY .ph vv.xwfxo.fd |
3# rvzgV 1FECedc ks. \n{frzx gi.r{hyz-xx |
#include <stdio.h> #include <string.h> int main() { char str[1000],str1[1000]; int i,k,j,n,m,l,T; scanf("%d",&T); getchar(); while(T--) { gets(str); k = strlen(str); for(i=0;i<k;i++) { if((str[i]>='A' && str[i]<='Z') || (str[i]>='a'&& str[i]<='z')) str[i] = str[i] + 3; } n=0; for(j=k-1;j>=0;j--) { str1[n] = str[j]; n++; } str1[n] = '\0'; l = k/2; for(i=l;i<k;i++) { str1[i] = str1[i] - 1; } printf("%s\n",str1); } return 0; }
Beecrowd Problem 1025
Raju and Meena love to play with Marbles. They have a lot of marbles with numbers written on them. In the beginning, Raju would place the marbles one after another in ascending order of the numbers written on them. Then, Meena would ask Raju to find the first marble with a certain number. She would count 1…2…3. Raju gets one point for correct answer, and Meena gets the point if Raju fails. After some fixed number of attempts, the game ends and the player with maximum points wins. Today it’s your chance to play as Raju. Being a smart kid, you have in your advantage the computer. But don’t underestimate Meena, she wrote a program to keep track how much time you’re taking to give all the answers. So now you have to write a program, which will help you in your role as Raju.
Input
There can be multiple test cases. The total number of test cases is less than 65. Each test case consists begins with 2 integers: N the number of marbles and Q the number of queries Meena would make. The next N lines would contain the numbers written on the N marbles. These marble numbers will not come in any particular order. Following Q lines will have Q queries. Be assured, none of the input numbers are greater than 10000 and none of them are negative.
Input is terminated by a test case where N = 0 and Q = 0.
Output
For each test case output there must be a serial number of the test case. For each query, write one line of output. The format of this line will depend on whether the number is consulted or not written in one of the marbles.
The two different formats are described below:
‘x found at y‘, if the first marble with number x was found at position y. Positions are numbered 1, 2,…, N.
‘x not found‘, if the marble with number x is not present.
Input Sample | Output Sample |
4 1 2 3 5 1 5 5 2 1 3 3 3 1 2 3 0 0 |
CASE# 1: 5 found at 4 CASE# 2: 2 not found 3 found at 3 |
#include <stdio.h> #include <stdlib.h> int ascending(const void *a, const void *b) { return (*(int *)a - *(int *)b); } int achar(int ac[], int len, int comp) { for (int k = 0; k < len; k++) { if (ac[k] == comp) { return k + 1; } } return 0; } int main() { int n, f, q, j, l; n = 0; for (;;) { scanf("%d", &f); scanf("%d", &q); if (f == 0 && q == 0) break; int *vet = malloc(f * sizeof(int)); for (j = 0; j < f; j++) { scanf("%d", &vet[j]); } qsort(vet, f, sizeof(int), ascending); printf("CASE# %d:\n", n + 1); for (j = 0; j < q; j++) { scanf("%d", &l); int m = achar(vet, f, l); if (m != 0) printf("%d found at %d\n", l, m); else printf("%d not found\n", l); } n++; free(vet); } return 0; }
Beecrowd Problem 1035
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.
Input Sample | Output Sample |
5 6 7 8 | Valores nao aceitos |
2 3 2 6 | Valores aceitos |
#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;
}
Beecrowd Problem 1036
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 (double) A, B and C.
Output
Print the result with 5 digits after the decimal point or the message if it is impossible to calculate.
Input Samples | Output Samples |
10.0 20.1 5.1 | R1 = -0.29788 R2 = -1.71212 |
0.0 20.0 5.0 | Impossivel calcular |
10.3 203.0 5.0 | R1 = -0.02466 R2 = -19.68408 |
10.0 3.0 5.0 | Impossivel calcular |
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, d, r1, r2;
scanf(“%f %f %f”, & a, & b, & c);
d = (pow(b, 2) – (4 * a * c));
r1 = ((-b + sqrt(d)) / (2 * a));
r2 = ((-b – sqrt(d)) / (2 * a));
if (a != 0 && d > 0)
printf(“R1 = %.5lf\nR2 = %.5lf\n”, r1, r2);
else
printf(“Impossivel calcular\n”);
return 0;
}
Beecrowd Problem 1037
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.
Input Sample | Output Sample |
25.01 | Intervalo (25,50] |
25.00 | Intervalo [0,25] |
100.00 | Intervalo (75,100] |
-25.02 | Fora de intervalo |
#include<stdio.h>
int main()
{
float n;
scanf(“%f”, &n);
if(n < 0 || n > 100){
printf(“Fora de intervalo\n”);
}else{
if(n >= 0 && n <= 25){
printf(“Intervalo [0,25]\n”);
}else if(n > 25 && n <= 50){
printf(“Intervalo (25,50]\n”);
}else if(n > 50 && n <= 75){
printf(“Intervalo (50,75]\n”);
}else{
printf(“Intervalo (75,100]\n”);
}
}
return 0;
}
Beecrowd Problem 1038
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.
Input Sample | Output Sample |
3 2 | Total: R$ 10.00 |
4 3 | Total: R$ 6.00 |
2 3 | Total: R$ 13.50 |
#include<stdio.h>
int main()
{
int X, Y;
float price = 0;
scanf(“%d %d”, &X, &Y);
if (X == 1)
{
price = (float) (4.00 * Y);
}
else if (X == 2)
{
price = (float) (4.50 * Y);
}
else if (X == 3)
{
price = (float) (5.00 * Y);
}
else if (X == 4)
{
price = (float) (2.00 * Y);
}
else if (X == 5)
{
price = (float) (1.50 * Y);
}
printf(“Total: R$ %.2f\n”,price);
}
Beecrowd Problem 1040
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 Sample | Output 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.0 | Media: 4.8 Aluno reprovado. |
9.0 4.0 8.5 9.0 | Media: 7.3 Aluno aprovado. |
#include <stdio.h>
int main()
{
double first, second, third, fourth, last, sum;
scanf(“%lf %lf %lf %lf”, &first, &second, &third, &fourth);
sum = (first * 2 + second * 3 + third * 4 + fourth) / 10;
printf(“Media: %.1f\n”, sum);
if (sum >= 7.0){
printf(“Aluno aprovado.\n”);
}
else if (sum >= 5.0)
{
printf(“Aluno em exame.\n”);
scanf(“%lf”, &last);
printf(“Nota do exame: %.1f\n”, last);
if (last + sum / 2.0 > 5.0){
printf(“Aluno aprovado.\n”);
}
else{
printf(“Aluno reprovado.\n”);
}
printf(“Media final: %.1f\n”, (last + sum ) / 2.0);
}
else{
printf(“Aluno reprovado.\n”);
}
return 0;
}
Thank You!
Leave a Reply