zoukankan      html  css  js  c++  java
  • UVA11827(GCD)鬼输入

        题目:给你一组数,求出其中两两最大公约数中最大的值

          解析:数论,小数据直接枚举。

        坑点:输入,可能有多余空格,TL问题

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<map>
    using namespace std;
    typedef long long ll;
    const int maxn=1e2+10;
    int a[maxn];
    int maxx=-1;
    int gcd(int a,int b)
    {
        return b?gcd(b,a%b):a;      ///
    }
    int main()
    {
        int t;char ch;
        scanf("%d",&t);
        getchar();
        while(t--)
        {
            char s[maxn];
            gets(s);
            int to=0,cnt=0;
            int num[maxn];
            for(int i=0;s[i]!='';i++)
            {
                if(s[i]==' ')
                {
                    num[cnt++]=to;
                    to=0;
                }
                else
                    to=to*10+s[i]-'0';
            }
            if(to)
                num[cnt++]=to;
            maxx=-1;
            for(int i=0;i<cnt;i++)
            {
                for(int j=i+1;j<cnt;j++)
                    {
                        maxx=max(maxx,gcd(num[i],num[j]));
                    }
            }
            cout<<maxx<<endl;
        }
    }
  • 相关阅读:
    Python生成器表达式
    Python列表解析
    Python迭代器(Iterator)
    Python set 集合
    python eval 函数妙用
    Python字典 (dict)
    Python序列之元组 (tuple)
    Python序列之列表 (list)
    递归和反射
    常用标准库
  • 原文地址:https://www.cnblogs.com/liyexin/p/12449463.html
Copyright © 2011-2022 走看看