-
Notifications
You must be signed in to change notification settings - Fork 34
/
1027-A-Dangerous-Maze.cpp
88 lines (64 loc) · 1013 Bytes
/
1027-A-Dangerous-Maze.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <stdio.h>
#include <utility>
#include <algorithm>
using namespace std;
pair <int, int> minify(pair <int, int> temp)
{
int x;
int y;
int ok;
x = temp.first;
y = temp.second;
ok = 1;
while(ok) {
ok = 0;
for (int i = 2; i <= y; i++) {
if(x % i == 0 and y % i == 0) {
ok = 1;
x = x / i;
y = y / i;
}
}
}
temp.first = x;
temp.second = y;
return temp;
}
int main()
{
int t;
int psum;
int nsum;
int n;
int ncount;
int x;
int y;
pair <int, int> temp;
scanf("%d", &t);
for (int cases = 1; cases <= t; cases++) {
scanf("%d", &n);
nsum = 0;
psum = 0;
ncount = 0;
for(int i = 0; i < n; i++) {
scanf("%d", &x);
if(x < 0) {
ncount++;
nsum += abs(x);
}
else {
nsum += x;
}
}
if(ncount == n) {
printf("Case %d: inf\n", cases);
}
else {
temp.first = nsum;
temp.second = n - ncount;
temp = minify(temp);
printf("Case %d: %d/%d\n",cases, temp.first, temp.second);
}
}
}