337BRoutine Problem

 1 /*给出你图片的长和宽的比例a:b 和摄像头的比例c:d,然后叫你求最后将图片放进摄像头
 2 以后,剩余的面积比上摄像头的总面积,注意要化简为最简形式,而且摄像头要设置成至少一条边和图片相等
 3 做法;先将两个比例式子通分,分别比较分母和分子,通分以后必定有一条边是相等的,所以只要比较另一条边就可以了
 4 */
 5 #include <iostream>
 6 #include<string.h>
 7 #include<stdio.h>
 8 #include<math.h>
 9 using namespace std;
10 int gcd(int x,int y)
11 {
12     int t=1;
13     while(t!=0)
14     {t=x%y;x=y;y=t;}
15     return x;
16 }
17 void f(int a,int b)
18 {
19     int g;
20     g=gcd(a,b);
21     while(g>1)
22     {
23         a/=g;
24         b/=g;
25         g=gcd(a,b);
26     }
27     if(a<b)
28         printf("%d/%d
",a,b);
29     else
30         printf("%d/%d
",b,a);
31 }
32 int int_abs(int a) {return a>0?a:-a;}
33 int main()
34 {
35     int x,y,X,Y,g,a,b,A,B;
36     while(scanf("%d%d%d%d",&x,&y,&X,&Y)!=EOF)
37     {
38         a=x*Y;
39         b=y*Y;
40         A=X*y;
41         B=Y*y;
42         if(a>A)
43              f(abs(a-A),a>A?a:A);
44          else
45          {
46              a=x*X;
47             b=y*X;
48             A=X*x;
49             B=Y*x;
50             f(abs(b-B),b>B?b:B);
51          }
52     }
53     return 0;
54 }
原文地址:https://www.cnblogs.com/okboy/p/3263804.html