Sunday, May 1, 2016

URI Online Judge Solution 1072 Interval 2

Main link: https://www.urionlinejudge.com.br/judge/en/problems/view/1072



URI Online Judge | 1072

Interval 2

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Read an integer N. This N will be the number of integer numbers that will be read.
Print how many these numbers are in the interval [10,20] and how many values are out of this interval.

Input

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

Output

For each test case, print how many numbers are in and how many values are out of the interval.
Input SampleOutput Sample
4
14
123
10
-25
2 in
2 out


URI Online Judge Solution  1072 in Java



import java.io.IOException;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {
    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+" in\n"+out +" out\n");
    }

}




2 comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.