一道挺简单的数论题,但是数论不是主要的问题,输入是主要的问题,使用了一个比较奇特的输入方法,使读入的一串字符串形成一个输入流
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdio>
#include <queue>
#include <map>
#include <algorithm>
#include <stack>
#include <utility>
#include <set>
#include<sstream>
typedef unsigned long long ll;
using namespace std;
const int mx = 106;
int n,num[mx];
string s;
int gcd(int a, int b)
{
return a%b?gcd(b, a%b):b;
}
char a;
int main ()
{
int n,cnt,i,j,k,ans;
scanf("%d\n",&n);
while (n --)
{
ans = 1;
cnt = 0;
getline(cin, s);
stringstream ss(s);
cnt = 0;
while (ss >> num[cnt]) // 从ss中取数
cnt++;
for(i = 0; i < cnt; i++)
for(j = i + 1; j < cnt; j++)
ans = max(ans,gcd(num[i],num[j]));
printf("%d\n",ans);
}
}
本文介绍了一道数论题目,重点在于一种特殊的输入方法。通过使用stringstream处理输入流,实现了从一串字符串中读取多个整数,并计算这些整数间最大公约数的最大值。
6961

被折叠的 条评论
为什么被折叠?



