Algorithm
Problem Name: beecrowd | 2936
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2936
How Much Cassava?
By Felipe C. Ochial, URI Brazil
Timelimit: 1
Every year in April, the Curupira, Boitatá, the pink Boto (this one in his man form, as Dona Chica likes it better), Mapinguari and Iara meet at Dona Chica to remember their moments with Mani, the beautiful girl with the white skin. And as it could not be different the main dish of this meeting is the cassava. Each one of them eats one to ten servings of cassava and they always warn Dona. Chica in advance about how many servings they will eat that day. The size of the portion of each is different, but they are always the same. The portions are as follows (in grams):
-
Curupira eats 300
-
Boitatá eats 1500
-
Boto eats 600
-
Mapinguari eats 1000
-
Iara eats 150
Dona chica in turn always eats 225 grams of cassava. Tired of every year having to figure out how much cassava to prepare she contacted you to write a program that tells how much cassava should be prepared in grams.
Input
The input consists of 5 integers each representing the portions that the guests of Dona Chica will consume. The first integer represents the portions of Curupira, the second of Boitatá, the third of Boto, the fourth of Mapinguari and the fifth of Iara.
Output
The output consists of a single integer representing how much cassava Dona Chica should prepare in grams. Do not forget the line break after the awnser :).
Input Samples | Output Samples |
1 1 1 1 1 |
3775 |
2 2 2 2 2 |
7325 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#define true 1
#define false 0
int main(int argc, char **argv)
{
int vet[5] = { 300, 1500, 600, 1000, 150 };
int n, ans, i;
ans = 0;
for (i = 0; i < 5; ++i)
scanf("%d", &n), ans += n * vet[i];
ans += 225;
printf("%d\n", ans);
return 0;
}
Copy The Code &
Try With Live Editor
#2 Code Example with Java Programming
Code -
Java Programming
import java.util.*;
public class Main {
public static final int[] porcoes = { 300, 1500, 600, 1000, 150 };
public static void main(String[] args) throws Exception {
Scanner leitor = new Scanner(System.in);
int total = 225;
for (int i = 0; i < 5; i++) {
total += leitor.nextInt() * porcoes[i];
}
System.out.println(total);
}
}
Copy The Code &
Try With Live Editor
#3 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("fs")
const quantitiesPerNames = readFileSync("/dev/stdin", "utf8")
.split("\n", 5)
.map(line => Number.parseInt(line, 10))
const portions = new Map([
["Curupira", 300],
["Boitatá", 1500],
["Boto", 600],
["Mapinguari", 1000],
["Iara", 150],
]) // massa em gramas
function main() {
const DEFAULT_MASS = 225
const portionsMassIndexes = Array.from(portions.values())
const totalMass = quantitiesPerNames.reduce((sum, quantity, index) => sum + quantity * portionsMassIndexes[index], DEFAULT_MASS)
console.log(totalMass)
}
main()
Copy The Code &
Try With Live Editor