Algorithm


Problem Name:  beecrowd | 1066
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1066

Even, Odd, Positive and Negative

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Make a program that reads five integer values. Count how many   of these values are even, odd, positive and negative. Print these information like following example.

Input

The input will be 5 integer values.

Output

Print a message like the following example with all letters in lowercase, indicating how many of these values ​​are even, odd, positive and negative.

Input Sample Output Sample

-5
0
-3
-4
12

3 valor(es) par(es)
2 valor(es) impar(es)
1 valor(es) positivo(s)
3 valor(es) negativo(s)

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main()
{
    int n, i;
    int pos = 0, neg = 0, par = 0, im = 0;

    for(i = 0; i  <  5; ++i)
    {
        scanf("%d", &n);
        if(n > 0) {
            pos++;
        } else {
            if(n != 0){
                neg++;
            }
        }

        if(n % 2 == 0) {
            par++;
        } else {
            im++;
        }
    }

    printf("%d valor(es) par(es)n", par);
    printf("%d valor(es) impar(es)n", im);
    printf("%d valor(es) positivo(s)n", pos);
    printf("%d valor(es) negativo(s)n", neg);

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
-5 0 -3 -4 12

Output

x
+
cmd
3 valor(es) par(es) 2 valor(es) impar(es) 1 valor(es) positivo(s) 3 valor(es) negativo(s)

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>

using namespace std;

int main()
{
    int n;
    int pos = 0, neg = 0, par = 0, im = 0;

    for(int i = 0; i  <  5; ++i)
    {
        cin >> n;
        if(n > 0) {
            pos++;
        } else {
            if(n != 0) {
                neg++;
            }
        }

        if(n % 2 == 0) {
            par++;
        } else {
            im++;
        }
    }

    cout << par << " valor(es) par(es)" << endl;
    cout << im << " valor(es) impar(es)" << endl;
    cout << pos << " valor(es) positivo(s)" << endl;
    cout << neg << " valor(es) negativo(s)" << endl;

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
-5 0 -3 -4 12

Output

x
+
cmd
3 valor(es) par(es) 2 valor(es) impar(es) 1 valor(es) positivo(s) 3 valor(es) negativo(s)

#3 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        int X, even = 0,odd = 0,positive = 0,negative = 0;
        Scanner input =new Scanner(System.in);
        for (int i = 1; i  < = 5; i++) {
            X = input.nextInt();
            if (X % 2 == 0) {
                even += 1;
            }
                if (X % 2 != 0) {
                odd += 1;
            }
                if (X > 0) {
                positive += 1;
            }
                if (X  <  0) {
                negative += 1;
            }

        }
        System.out.print(even+" valor(es) par(es)n");
        System.out.print(odd+" valor(es) impar(es)n");
        System.out.print(positive+" valor(es) positivo(s)n");
        System.out.print(negative+" valor(es) negativo(s)n");

    }
 
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
-5 0 -3 -4 12

Output

x
+
cmd
3 valor(es) par(es) 2 valor(es) impar(es) 1 valor(es) positivo(s) 3 valor(es) negativo(s)

#4 Code Example with Python Programming

Code - Python Programming


even=0
odd=0
positive=0
negative=0
for i in range(5):
    n = float(input())
    if(n % 2 == 0):
         even = even+1
    else:
        odd =odd+1
    if (n > 0):
        positive =positive+1
    elif (n < 0):
        negative =negative+1
print(f"{even} valor(es) par(es)")
print(f"{odd} valor(es) impar(es)")
print(f"{positive} valor(es) positivo(s)")
print(f"{negative} valor(es) negativo(s)">
Copy The Code & Try With Live Editor

Input

x
+
cmd
-5 0 -3 -4 12

Output

x
+
cmd
3 valor(es) par(es) 2 valor(es) impar(es) 1 valor(es) positivo(s) 3 valor(es) negativo(s)
Advertisements

Demonstration


Previous
#1065 Beecrowd Online Judge Solution 1065 Even Between five Numbers - Solution in C, C++, Java, Python and C#
Next
#1067 Beecrowd Online Judge Solution 1067 Odd Numbers - Solution in C, C++, Java, Python and C#