-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloj1027.cpp
63 lines (50 loc) · 960 Bytes
/
loj1027.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
using namespace std;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define abss(x) (((x) < 0) ? - (x) : (x))
bool cmp(double a,int b)
{
return a>b;
}
int gcd(int a,int b)
{
if(b==0)
return a;
return gcd(b,a%b);
}
int main()
{
int T,x,i,Case=1,n,gs,cnt,sum;
scanf("%d",&T);
while(T--)
{
cnt=0,sum=0;;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&x);
if(x<0)
cnt++;
sum+=abss(x);
}
if(cnt==n)
printf("Case %d: inf\n",Case++);
else
{
cnt=n-cnt;
gs=gcd(sum,cnt);
while(1)
{
if(gs==1)
break;
sum/=gs;
cnt/=gs;
gs=gcd(sum,cnt);
}
printf("Case %d: %d/%d\n",Case++,sum,cnt);
}
}
return 0;
}