[ZJ]b112: 高中運動會
題目:
http://zerojudge.tw/ShowProblem?problemid=b112
-------------------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
int ans = 0;
while(b != 0)
{
ans = a % b;
a = b;
b = ans;
}
return a;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int a,b;
scanf("%d",&a);
while(n-->1)
{
scanf("%d",&b);
a = gcd(a,b);
}
printf("%d\n",a);
}
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=b112
-------------------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
int ans = 0;
while(b != 0)
{
ans = a % b;
a = b;
b = ans;
}
return a;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int a,b;
scanf("%d",&a);
while(n-->1)
{
scanf("%d",&b);
a = gcd(a,b);
}
printf("%d\n",a);
}
return 0;
}
留言
張貼留言