Algorithm
Problem Name: 2 AD-HOC - beecrowd | 1796 | [PJ]
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1796
Brazilian Economy
By Carlos Andrade, UFMS Brazil
Timelimit: 2
Lately Brazilian economy has become the subject of all the newspapers. Brazilian people have different opinions about the current economic scenario. Your task is to take a look at a survey and find out if the majority of Brazilians are ok or not ok with the current economic scenario.
Input
The first line contains an integer Q (4 ≤ Q ≤ 233000) representing how many citizens joined this survey. The second line contains Q integers Vi (0 ≤ Vi ≤ 1, 1 ≤ i ≤ Q) representing the opinion of the i-th Brazilian citizen surveyed about the current economic scenario. Where "0" represents the ones who answered that are ok with the current economic scenario and "1" the ones who are not ok.
Output
Your program should print "Y" if the majority answered that are ok with the economic scenario. Otherwise print "N".
Input Sample | Output Sample |
5 1 1 1 1 1 |
N |
4 1 1 0 0 |
N |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main(void) {
int n, z = 0, u = 0, i, x;
scanf("%d", &n);
for (i = 0; i < n; ++i) {
scanf("%d", &x);
if (x) ++u;
else ++z;
}
if (z > u) printf("Y");
else printf("N");
printf("\n");
return 0;
}
Copy The Code &
Try With Live Editor
Input
1 1 1 1 1
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
using namespace std;
int main(void) {
int n, z = 0, u = 0, i, x;
cin >> n;
for (i = 0; i < n; ++i) {
cin >> x;
if (x) ++u;
else ++z;
}
if (z > u) cout << "Y";
else cout << "N";
cout << endl;
return 0;
}
Copy The Code &
Try With Live Editor
Input
1 1 1 1 1
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("node:fs")
const [totalPeopleOpinions, ...opinions] = readFileSync("/dev/stdin", "utf8")
.split(/\s+/g)
.map((value) => Number.parseInt(value, 10))
function main() {
let desaprovedOpinionsQuantity = 0
for (let index = 0; index < totalPeopleOpinions; index++)
if (opinions[index] == 1)
desaprovedOpinionsQuantity += 1
const percentilOfDesaprovedOpinionsQuantity = desaprovedOpinionsQuantity / totalPeopleOpinions
console.log(percentilOfDesaprovedOpinionsQuantity < 0.5 ? "Y" : "N")
}
main()
Copy The Code &
Try With Live Editor
Input
1 1 1 1 1
Output
#4 Code Example with Python Programming
Code -
Python Programming
n = int(input())
e = str(input())
z = e.count('0')
u = e.count('1')
if z > u: print('Y')
else: print('N')
Copy The Code &
Try With Live Editor
Input
1 1 1 1 1
Output