http://acm.pku.edu.cn/JudgeOnline/problem?id=2272
题意是求两射击员的得分,然后比较谁胜利了。
#include <stdio.h> #include <math.h> int distance(double x,double y)//计算得分的函数 { double dis; dis = sqrt(x*x + y*y);//计算半径 if(dis <= 3) return 100; else if(dis <= 6) return 80; else if(dis <= 9) return 60; else if(dis <= 12) return 40; else if(dis <= 15) return 20; else return 0; } void Work() { double a,b; int i,j,flag; int score[2]; while(1) { flag = 0; for(i = 0;i < 2;i ++) { score[i] = 0; for(j = 0;j < 3;j ++) { scanf("%lf%lf",&a,&b); if(a == -100) { flag = 1; break; } score[i] = score[i] + distance(a,b);//分数累加 } if(flag) break; }
//比较分数 if(flag) break; if(score[0] == score[1]) printf("SCORE: %d to %d, TIE./n",score[0],score[1]); else if(score[0] < score[1]) printf("SCORE: %d to %d, PLAYER 2 WINS./n",score[0],score[1]); else if(score[0] > score[1]) printf("SCORE: %d to %d, PLAYER 1 WINS./n",score[0],score[1]); } } int main() { Work(); return 0; }
/*
-9 0 0 -4.5 -2 2 9 0 0 4.5 2 -2
-19.0 19.0 0 0 0 0 3 3 6 6 12 12
-100 0 0 0 0 0 0 0 0 0 0 0
SCORE: 240 to 240, TIE.
SCORE: 200 to 140, PLAYER 1 WINS.
*/