1.测试点4错误版:丙的分数可能是浮点数,没有考虑到这一点甚至还限制了整除的我qaq。而且将甲乙的分数用两个参数表示,逻辑上没问题,但有两层循环。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int mine,X,Y;
int flag,i,j;
flag = 0;
if(scanf("%d%d%d",&mine,&X,&Y));
int sc[3] = {0};
for(i = 9;i> 0;i--){
for(j = 9;j >= 0;j--){
if( ((int)fabs(9*(i-j))/X == (10*j+i)/Y) && ((10*j+i) % Y == 0) && ((int)fabs(9*(i-j))% X ==0) ){
sc[0] = 10*i+j;
sc[1] = 10*j+i;
sc[2] = (10*j+i)/Y;
flag = 1;
break;
}
}
if(flag == 1)
break;
}
if(flag == 1){
printf("%d",sc[0]);
for(i = 0;i<3;i++){
if(sc[i]>mine)
printf(" Cong");
else
if(sc[i]<mine)
printf(" Gai");
else
printf(" Ping");
}
}else
printf("No Solution");
return 0;
}
2:完全正确版。又又又又犯了double输出为%d的错误,这点没处理好的话甲的分数输出为0。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int rev(int num){
int a,b;
a = num%10;
b = num/10;
return 10*a+b;
}
int main(int argc, char *argv[]) {
int mine,X,Y;
int flag,i,yi;
flag = 0;
if(scanf("%d%d%d",&mine,&X,&Y));
double sc[3] = {0};
for(i = 99;i>9;i--){
yi = rev(i);
if(fabs((double)yi/Y - fabs(i-yi)/X )<0.00001){
sc[0] = i;
sc[1] = yi;
sc[2] = (double)yi/X;
flag = 1;
break;
}
}
if(flag == 1){
printf("%d",(int)sc[0]);
for(i = 0;i<3;i++){
if(sc[i]>mine)
printf(" Cong");
else
if(sc[i]<mine)
printf(" Gai");
else
printf(" Ping");
}
}else
printf("No Solution");
return 0;
}