Competitive Programming Solutions

GitHub
back to dashboard

C. Even, Odd, Positive and Negative

Codeforces - Sheet #2 (Loops) · limit: 1s · memory: 256MB · view on codeforces

input

5
-5 0 -3 -4 12

output

Even: 3
Odd: 2
Positive: 1
Negative: 3
Main.java
static void solve() {

        // Write your solution here
        int n = in.nextInt();
        int even = 0, odd = 0, negative = 0, positive = 0;
        while (n-- > 0) {
            int x = in.nextInt();
            if (x % 2 == 0) even++;
            else odd++;
            if (x < 0) negative++;
            else if (x > 0) positive++;
        }
        out.println("Even: " + even);
        out.println("Odd: " + odd);
        out.println("Positive: " + positive);
        out.println("Negative: " + negative);
    }