URI Online Judge | 1028
Collectable Cards
By Neilor Tonin, URI Brazil
Timelimit: 1Input
The first input line contains a single integer N (1 ≤ N ≤ 3000), indicating the number of test cases. Each test case contains two integer numbers F1 (1 ≤ F1 ≤ 1000) and F2 (1 ≤ F2 ≤ 1000) indicating, respectly, the among of collectable cards that Richard and Vicent have to change.
Output
For each test case there will be an integer number at the output, representing the maximum size of the stack of cards which can be exchanged between two players.
Input Sample | Output Sample |
3 8 12 9 27 259 111 | 4 9 37 |
URI Online Judge Solution || 1028 Collectable Cards in C language
#include <stdio.h>
int
main()
{
int
i, n, a, b;
int
dividendo, divisor, c;
scanf
(
"%d"
, &n);
for
( i = 0; i < n; ++i)
{
scanf
(
"%d%d"
, &a, &b);
if
(b > a){
dividendo = b;
divisor = a;
}
else
{
dividendo = a;
divisor = b;
}
while
(dividendo % divisor != 0)
{
c = dividendo % divisor;
dividendo = divisor;
divisor = c;
}
printf
(
"%d\n"
, divisor);
}
return
0;
}
Solution in C++ language:
#include <iostream>
using namespace std;
int main()
{
int n, a, b;
int dividendo, divisor, c;
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> a >> b;
if(b > a){
dividendo = b;
divisor = a;
}else{
dividendo = a;
divisor = b;
}
while(dividendo % divisor != 0)
{
c = dividendo % divisor;
dividendo = divisor;
divisor = c;
}
cout << divisor << endl;
}
return 0;
}
See or download code from dropbox
See in URI
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks