ZOJ1045&&1048
两道简单题,此外,1049有网友给出的计算公式是 Z=3.14*(x*x+y*y)/100.0+1.0,可惜我不明白其原理
ZOJ1045 HangOver
#include<iostream>
using namespace std;
int main()
{
double target,num,sum;
while(cin>>target&&target!=0.00)
{
sum = 0.0f;
num = 2;
while(sum<target)
{
sum += 1.0/num;
num++;
}
cout<<num-2<<" card(s)"<<endl;
}
return 0;
}
using namespace std;
int main()
{
double target,num,sum;
while(cin>>target&&target!=0.00)
{
sum = 0.0f;
num = 2;
while(sum<target)
{
sum += 1.0/num;
num++;
}
cout<<num-2<<" card(s)"<<endl;
}
return 0;
}
ZOJ1048 Financial Management
#include<iostream>
using namespace std;
int main()
{
double sum = 0.0f,average = 0.0f,num;
for (int i=0;i<12;++i)
{
cin>>num;
sum += num;
}
average = sum/12.0f;
cout<<"$"<<average<<endl;
return 0;
}
using namespace std;
int main()
{
double sum = 0.0f,average = 0.0f,num;
for (int i=0;i<12;++i)
{
cin>>num;
sum += num;
}
average = sum/12.0f;
cout<<"$"<<average<<endl;
return 0;
}
作者:洞庭散人
出处:http://phinecos.cnblogs.com/
本博客遵从Creative Commons Attribution 3.0 License,若用于非商业目的,您可以自由转载,但请保留原作者信息和文章链接URL。
posted on 2008-10-23 21:30 Phinecos(洞庭散人) 阅读(633) 评论(0) 编辑 收藏 举报