UVA 11827 Maximum GCD
来源:互联网 发布:光盘数据恢复软件 编辑:程序博客网 时间:2024/05/23 22:49
Maximum GCD
Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possiblepair of these integers.
Input
The first line of input is an integer N (1 < N < 100) that determines the number of test cases.The following N lines are the N test cases. Each test case contains M (1 < M < 100) positiveintegers that you have to find the maximum of GCD.
OutputFor
each test case show the maximum GCD of every possible pair.
Sample Input
3
10 20 30 40
7 5 12
125 15 25
Sample Output
20
1
25
题意:给不超过一百个数,求两个数最大的gcd
水题,数据范围小,直接暴力过,但是WA了n发,这题输入的数据是真的傲娇,第一次见这样玩的,让人无语了,各种前导空格后导空格,= =,一不小心就错
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<stack>#include<queue>#include<deque>#include<set>#include<map>#include<cmath>#include<vector>using namespace std;typedef long long ll;typedef pair<int, int> PII;#define pi acos(-1.0)#define eps 1e-10#define pf printf#define sf scanf#define lson rt<<1,l,m#define rson rt<<1|1,m+1,r#define e tree[rt]#define _s second#define _f first#define all(x) (x).begin,(x).end#define mem(i,a) memset(i,a,sizeof i)#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)#define mi ((l+r)>>1)const int inf=0x3f3f3f3f;char s[1110000];int T, a[1000];int gcd(int a,int b){ return !b?a:gcd(b,a%b);}int main(){ sf("%d",&T); getchar(); while(T--) { mem(a,0); int ans=0; int p=0; gets(s);//题目没说有多少组数据,只能输入字符串了,scanf("%s",s);这种输入不会读入空格不和题意 int d=strlen(s); int tag=0; for0(i,d) { if(s[i]!=' ') a[p]=a[p]*10+s[i]-'0',tag=1; else if(s[i]==' '&&tag)//如果前面是数字,当前为空格才令计数器加1 p++,tag=0; } if(!tag)//如果最后还有空格当前计数器减一 p--; for(int i=0;i<p;i++) for(int j=i+1;j<=p;j++) ans=max(ans,gcd(a[i],a[j])); pf("%d\n",ans); } return 0;}
阅读全文
0 0
- UVA 11827 Maximum GCD gcd
- UVa 11827 Maximum GCD
- UVA 11827-Maximum GCD
- UVa 11827 - Maximum GCD
- UVA 11827 - Maximum GCD
- UVA 11827 Maximum GCD
- UVa 11827 Maximum GCD
- UVA 11827Maximum GCD
- UVA 11827 Maximum GCD
- UVA 11827 Maximum GCD
- UVa 11827 Maximum GCD (gcd&读入技巧)
- UVA 11827 Maximum GCD gcd 读入技巧
- UVA 11827 Maximum GCD【GCD,stringstream】
- UVA 11827 Maximum GCD(gcd, getline)
- Uva——11827 Maximum gcd
- Maximum GCD UVA
- Maximum GCD - UVa 11827 最大公约数 读入有坑
- UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)
- python学习之运维应用
- 网络上找的JS日期格式化简洁版
- STL学习笔记10— —容器的选用
- [RK3288][Android6.0] 开发者选项中的Strict mode功能
- 使用最大公约数求线段上格点的个数
- UVA 11827 Maximum GCD
- FreeBSD代码目录说明
- SpringMVC中MessageSource的获取方法
- oracle的sql语句的练习题及答案(员工表+部门表)
- webpack编译多页面vue项目的配置问题
- js格式化json/xml格式
- 复杂链表的复制【每日一题】
- 学习贴 量化小白成长记---基础学习篇
- 获取Mat元素的方法使用M.at(i,j)