UVA 11827 水

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2927

题意:给你n行,每行有一些数,求这些数两两的最大公约数最大;

思路:字符串模拟,不然wa,然后暴力就好了;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define esp 1e-13
const int N=1e4+10,M=1e6+50000,inf=1e9+10,mod=1000000007;
int a[N];
char ch[M];
int main()
{
    int x,y,i,z,t;
    int T;
    scanf("%d",&T);
    getchar();
    while(T--)
    {
        int flag=1;
        gets(ch);
        y=strlen(ch);
        int sum=0;
        for(i=0;i<y;i++)
        {
            if(ch[i]>='0'&&ch[i]<='9')
            sum=sum*10+ch[i]-'0';
            else
            {
                if(sum)
                a[flag++]=sum;
                sum=0;
            }
        }
        if(sum)
        a[flag++]=sum;
        int ans=1;
        for(i=1;i<flag;i++)
        {
            for(t=i+1;t<flag;t++)
            ans=max(ans,__gcd(a[i],a[t]));
        }
        printf("%d
",ans);
    }

    return 0;
}
原文地址:https://www.cnblogs.com/jhz033/p/5763899.html