Algorithm
Problem Name: beecrowd | 1134
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1134
Type of Fuel
Adapted by Neilor Tonin, URI Brazil
A gas station wants to determine which of their products is the preference of their customers. Write a program to read the type of fuel supplied (coded as follows: 1. Alcohol 2. Gasoline 3. Diesel 4. End). If you enter an invalid code (outside the range of 1 to 4) a new code must be requested. The program will end when the inserted code is the number 4.
Input
The input contains only integer and positive values.
Output
It should be written the message: "MUITO OBRIGADO" and the amount of customers who fueled each fuel type, as an example.
Input Sample | Output Sample |
8 |
MUITO OBRIGADO |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int main(){
int a = 0;
int g = 0;
int d = 0;
while(1){
int num;
cin >> num;
if (num == 4){
break;
}
else if (num == 1){
a += 1;
}
else if (num == 2){
g += 1;
}
else if (num == 3){
d += 1;
}
else{
continue;
}
}
cout << "MUITO OBRIGADO" << endl;
cout << "Alcool: " << a << endl;
cout << "Gasolina: " << g << endl;
cout << "Diesel: " << d << endl;
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Java Programming
Code -
Java Programming
import java.io.IOException;
import java.util.Scanner;
public class Main{
public static void main(String[] args) throws IOException{
Scanner input = new Scanner(System.in);
int a = 0;
int g = 0;
int d = 0;
while(true){
int num = input.nextInt();
if (num == 4){
break;
}
else if (num == 1){
a += 1;
}
else if (num == 2){
g += 1;
}
else if (num == 3){
d += 1;
}
else{
continue;
}
}
System.out.println("MUITO OBRIGADO");
System.out.printf("Alcool: %d\n", a);
System.out.printf("Gasolina: %d\n", g);
System.out.printf("Diesel: %d\n", d);
}
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var a = 0;
var g = 0;
var d = 0;
while(true){
var num = parseInt(lines.shift());
if (num == 4){
break;
}
else if (num == 1){
a += 1;
}
else if (num == 2){
g += 1;
}
else if (num == 3){
d += 1;
}
else{
continue;
}
}
console.log("MUITO OBRIGADO");
console.log("Alcool: %d", a);
console.log("Gasolina: %d", g);
console.log("Diesel: %d", d);
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
a = 0
g = 0
d = 0
while(True):
num = int(input())
if (num == 4):
break
elif (num == 1):
a += 1
elif (num == 2):
g += 1
elif (num == 3):
d += 1
else:
continue
print("MUITO OBRIGADO")
print("Alcool: %d"% a)
print("Gasolina: %d"% g)
print("Diesel: %d"% d)
Copy The Code &
Try With Live Editor
Input
Output