题目链接:http://lightoj.com/volume_showproblem.php?problem=1027
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int sum,ans,n,m; int Gcd(int a,int b){ if(a%b == 0) return b; return Gcd(b,a%b); } int main() { //freopen("E:\acm\input.txt","r",stdin); int T; cin>>T; for(int cas=1;cas<=T;cas++){ scanf("%d",&n); m = n; sum = 0; for(int i=1;i<=n;i++){ int a; scanf("%d",&a); if(a<0) m--; sum += abs(a); } printf("Case %d: ",cas); if(m == 0) { printf("inf "); continue; } int G = Gcd(sum,m); printf("%d/%d ",sum/G,m/G); } }