Submission #6822

# Submission time Handle Problem Language Result Execution time Memory
6822 2014-07-08T02:47:00 Z gs12117 분수 (KPI13_fractions) C++
1 / 1
76 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(j==xl-2&&x[j+1]==2){
					j++;
					x[j]=1;
					j++;
					x[j]=2;
				}
				else{
					if(xl!=j+1&&x[j+1]==1){
						j+=2;
						x[j]++;
					}
					else{
						j++;
						x[j]=2;
					}
				}
			}
			else{
				x[j]++;
			}
		}
		else{
			if(j==xl-1&&y[j]+1==x[j]){
				if(j==yl-2&&y[j+1]==2){
					x[j]=y[j];
					j++;
					x[j]=1;
					j++;
					x[j]=2;
				}
				else{
					x[j]=y[j];
					if(yl!=j+1&&y[j+1]==1){
						j++;
						x[j]=1;
						j++;
						x[j]=y[j]+1;
					}
					else{
						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 Correct 0 ms 1088 KB Output is correct
5 Correct 0 ms 1088 KB Output is correct
6 Correct 0 ms 1088 KB Output is correct
7 Correct 0 ms 1088 KB Output is correct
8 Correct 0 ms 1088 KB Output is correct
9 Correct 0 ms 1088 KB Output is correct
10 Correct 0 ms 1088 KB Output is correct
11 Correct 0 ms 1088 KB Output is correct
12 Correct 0 ms 1088 KB Output is correct
13 Correct 0 ms 1088 KB Output is correct
14 Correct 0 ms 1088 KB Output is correct
15 Correct 0 ms 1088 KB Output is correct
16 Correct 0 ms 1088 KB Output is correct
17 Correct 32 ms 1088 KB Output is correct
18 Correct 32 ms 1088 KB Output is correct
19 Correct 32 ms 1088 KB Output is correct
20 Correct 32 ms 1088 KB Output is correct
21 Correct 32 ms 1088 KB Output is correct
22 Correct 24 ms 1088 KB Output is correct
23 Correct 32 ms 1088 KB Output is correct
24 Correct 28 ms 1088 KB Output is correct
25 Correct 0 ms 1088 KB Output is correct
26 Correct 36 ms 1088 KB Output is correct
27 Correct 48 ms 1088 KB Output is correct
28 Correct 56 ms 1088 KB Output is correct
29 Correct 48 ms 1088 KB Output is correct
30 Correct 40 ms 1088 KB Output is correct
31 Correct 40 ms 1088 KB Output is correct
32 Correct 40 ms 1088 KB Output is correct
33 Correct 48 ms 1088 KB Output is correct
34 Correct 4 ms 1088 KB Output is correct
35 Correct 76 ms 1088 KB Output is correct
36 Correct 72 ms 1088 KB Output is correct
37 Correct 68 ms 1088 KB Output is correct
38 Correct 64 ms 1088 KB Output is correct
39 Correct 76 ms 1088 KB Output is correct
40 Correct 72 ms 1088 KB Output is correct
41 Correct 64 ms 1088 KB Output is correct
42 Correct 64 ms 1088 KB Output is correct
43 Correct 64 ms 1088 KB Output is correct
44 Correct 76 ms 1088 KB Output is correct
45 Correct 76 ms 1088 KB Output is correct
46 Correct 76 ms 1088 KB Output is correct
47 Correct 76 ms 1088 KB Output is correct
48 Correct 68 ms 1088 KB Output is correct
49 Correct 64 ms 1088 KB Output is correct
50 Correct 68 ms 1088 KB Output is correct