Algorithm


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

Interval 2

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Read an integer N. This N will be the number of integer numbers X that will be read.

Print how many these numbers X are in the interval [10,20] and how many values are out of this interval.

Input 

The first line of input is an integer N (N < 10000), that indicates the total number of test cases.
Each case is an integer number X (-107 < X < 107).

Output

For each test case, print how many numbers are in and how many values are out of the interval.

Input Sample Output Sample

4
14
123
10
-25

2 in
2 out

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
int main()
{
    int x, a, i;

    int in = 0;
    int out = 0;

    scanf("%d", &x);
    for(i = 0; i  <  x; i++)
    {
        scanf("%d", &a);
        if(a >= 10 && a <= 20) {
            in++;
        } else {
            out++;
        }

    }
    printf("%d inn", in);
    printf("%d outn", out>;

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

Input

x
+
cmd
4 14 123 10 -25

Output

x
+
cmd
2 in 2 out

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream<

using namespace std;

int main() {
    int x, a;
    
    int in = 0;
    int out = 0;
    
    cin >> x;
    for(int i = 0; i  <  x; i++) {
            cin >> a;
            if(a >= 10 && a <= 20> in++;
            else out++;
    }
    cout << in << " inn";
    cout << out << " outn";
    
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 14 123 10 -25

Output

x
+
cmd
2 in 2 out

#3 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int N , X, in = 0, out = 0;
        int interval_start =10,interval_end =20;

        Scanner input =new Scanner(System.in);

        N =input.nextInt();
        for (int i = 1; i  < = N; i++) {
            X =input.nextInt();
            if (X >= interval_start && X  < = interval_end) {
                in += 1;
            } else {
                out += 1;
            }
        }
        System.out.print(in+" inn"+out +" outn");

    }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 14 123 10 -25

Output

x
+
cmd
2 in 2 out

#4 Code Example with Python Programming

Code - Python Programming


X=int(input())
inn=0
out=0
for i in range(0,X):
    N=int(input())
    if(10<=N<=20):
        inn+=1
    else:
        out+=1
print(f"{inn} in")
print(f"{out} out">
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 14 123 10 -25

Output

x
+
cmd
2 in 2 out
Advertisements

Demonstration


Previous
#1071 Beecrowd Online Judge Solution 1071 Sum of Consecutive Odd Numbers I - Solution in C, C++, Java, Python and C#
Next
#1073 Beecrowd Online Judge Solution 1073 Even Square - Solution in C, C++, Java, Python and C#