LightOJ 1027 - A Dangerous Maze(数论)

来源:互联网 发布:苏宁易购抢卷软件 编辑:程序博客网 时间:2024/05/08 07:08

题目链接:LightOJ 1027 - A Dangerous Maze

代码

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b); }int main () {    int cas;    scanf("%d", &cas);    for (int kcas = 1; kcas <= cas; kcas++) {        int n, x, s = 0, c = 0;        scanf("%d", &n);        for (int i = 0; i < n; i++) {            scanf("%d", &x);            if (x > 0) c++;            else x = -x;            s += x;        }        printf("Case %d: ", kcas);        if (c == 0) printf("inf\n");        else {            int d = gcd(s, c);            printf("%d/%d\n", s / d, c / d);        }    }    return 0;}
0 0
原创粉丝点击