http://poj.org/problem?id=1005
总结一下:
首先是他的格式,值得学习;
其次是他的变量放在for中间的方法值得学习;
最重要的积累是 PI的表示是acos(-1.0);
自己的:
#include <stdio.h>
#include <math.h>
#define PI acos(-1.0)
int judge(float a,float b)
{
float j;
j=(a*a+b*b);
for(int i=0;i<100;i++)
if(((50.0*i)/PI)>j/2) return (i);
}
int main()
{
int n,j;
float a,b;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%f%f",&a,&b);
j=judge(a,b);
printf("Property %d: This property will begin eroding in year %d.\n",i,j);
}
printf("END OF OUTPUT.\n");
return (0);
}
人家的:
#include<stdio.h>
#include<math.h>
#define PI acos(-1.0)
int main()
{
int n,i,years;
double x,y,dissqu;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%lf%lf",&x,&y);
dissqu=x*x+y*y;
for(years=1;100*years<PI*dissqu;years++);
printf("Property %d: This property will begin eroding in year %d.\n",i,years);
}
puts("END OF OUTPUT.");
return 0;
}