# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
6784 |
2014-07-07T10:06:45 Z |
gs12117 |
분수 (KPI13_fractions) |
C++ |
|
0 ms |
1088 KB |
#include<stdio.h>
int n;
int a,b,c,d;
int x[100];
int y[100];
int xl,yl;
int main(){
int i,j,t;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d%d%d%d",&a,&b,&c,&d);
for(xl=0;;xl++){
if(b==0)break;
x[xl]=a/b;
t=a%b;
a=b;
b=t;
}
for(yl=0;;yl++){
if(d==0)break;
y[yl]=c/d;
t=c%d;
c=d;
d=t;
}
for(j=0;;j++){
if(x[j]!=y[j]||j==xl||j==yl)break;
}
if(j==xl){
x[j]=y[j]+1;
}
else if(j==yl){
x[j]=x[j]+1;
}
else if(x[j]<y[j]){
if(j==yl-1&&x[j]+1==y[j]){
if(xl!=j+1&&x[j+1]==1){
x[j]++;
}
j++;
x[j]=2;
}
else{
x[j]++;
}
}
else{
if(j==xl-1&&y[j]+1==x[j]){
x[j]=y[j];
if(yl!=j+1&&y[j+1]==1){
x[j]++;
}
j++;
x[j]=2;
}
else{
x[j]=y[j]+1;
}
}
a=1;
b=0;
while(j>=0){
t=a;
a=b;
b=t;
a+=x[j]*b;
j--;
}
printf("%d %d\n",a,b);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1088 KB |
Output is correct |
2 |
Correct |
0 ms |
1088 KB |
Output is correct |
3 |
Correct |
0 ms |
1088 KB |
Output is correct |
4 |
Incorrect |
0 ms |
1088 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |