-
Notifications
You must be signed in to change notification settings - Fork 2
/
ALEXNUMB.rb
59 lines (38 loc) · 1.08 KB
/
ALEXNUMB.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Alexandra has some distinct integer numbers a1,a2...an.
# Count number of pairs (i,j) such that:
# 1≤ i ≤ n
# 1≤ j ≤ n
# ai < aj
# Input
# The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.The first line of each test case contains a single integer n denoting the number of numbers Alexandra has. The second line contains n space-separated distinct integers a1, a2, ..., an denoting these numbers.
# Output
# For each test case, output a single line containing number of pairs for corresponding test case.
# Constraints
# 1 ≤ T ≤ 4
# 1 ≤ n ≤ 100000
# 0 ≤ ai ≤ 109
# All the ai are distinct
# Example
# 2
# 2
# 2 1
# 3
# 3 1 2
# Output:
# 1
# 3
# Explanation
# Case 1: Only one such pair: (2,1)
# Case 2: 3 possible pairs: (2,1), (2,3), (3,1)
# URL :http://www.codechef.com/DEC13/problems/ALEXNUMB
#!/usr/bin/ruby
t = Integer(gets)
while t > 0
m= n = Integer(gets)
while n != 0
a = gets.chomp
n = 0 if a.split(" ").length == n
end
puts ( m * (m - 1) ) / 2
t -= 1
end