uva11827 处理下输入

/*0.012s*/
 
#include<cstdio>
#include<algorithm>
using namespace std;
 
int num[100], n;
 
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
 
int cal()
{
    int i, j, maxn = 0;
    for (i = 0; i < n - 1; ++i)
        for (j = i + 1; j < n; ++j)
            maxn = max(maxn, gcd(num[i], num[j]));
    return maxn;
}
 
int main()
{
    int t;
    char ch;
    scanf("%d
", &t);
    while (t--)
    {
        n = 0;
        while (true)
        {
            scanf("%d", &num[n++]);
            while ((ch = getchar()) == ' ')
                ;
        //    ungetc(ch, stdin);
            if (ch == 10 || ch == -1) break;
        }
        printf("%d
", cal());
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zsben991126/p/10447031.html