(1)辗转相除法必须得会;
(2)a1=a/x*x学会这种赋值手法;
(3)此题必须求取最大公约数,用x,y除以最大公约数的值进行计算;
(4)尤其是这道题的思路,必须弄清楚;
AC:
#include<stdio.h> int com_div(int a,int b)//辗转相除法 { int r; while(b!=0) { r=a%b; a=b; b=r; } return a; } int main() { int a,b,x,y,a1,b1,t,i; while(scanf("%d%d%d%d",&a,&b,&x,&y)!=EOF) { t=com_div(x,y); x=x/t; y=y/t; if(a<x||b<y) { printf("0 0 "); continue; } if(x>y) { for(a1=a/x*x;a1/x*y>b;a1-=x); b1=a1/x*y; } else { for(b1=b/y*y;b1/y*x>a;b1-=y); a1=b1/y*x; } printf("%d %d ",a1,b1); } return 0; }