数学H - The Land of Justice
2015-08-18 18:27
260 查看
因为看到输出这边是50
所以想用类型转换再用%d 各种过不去
改了%.0lf就过了
In the Land of Justice the selling price of everything is xed all over the country. Nobody can buy
a thing and sell it in double price. But, that created problems for the businessmen. They left their
business and went to the production. So, after some days everybody was in production and nobody
in business. And the people didn't get their necessary things though the country was self-sufficient in
every sector.
The government became very much anxious. But, they were intelligent enough to call the mathe-
maticians.
The mathematicians gave a solution. They suggested setting the surface area of an object as its
selling-unit instead of its volume. Actually the clever mathematicians were very much interested to
establish their own business.
Now, the government asks the programmers to build the software that would calculate the pro t
things.
Here your job is to calculate the business pro t for a solid sphere. A businessman buys a complete
sphere and to maximize his pro t he divides it in
n
equal parts. All cut should go through the axis of
the sphere. And every part should look like the picture below:
Input
You are given a sequence of integers
N
(0
<N<
2
31
), indicating the numbers of parts of the sphere.
The input le is terminated with a negative number. This number should not be processed.
Output
Calculate the pro t over the sold pieces. The result should be in percentage and rounded to the nearest
integer.
SampleInput
2
2
-1
SampleOutput
50%
50%
所以想用类型转换再用%d 各种过不去
改了%.0lf就过了
#include <stdio.h> #include <math.h> #define pi 3.14 int main(){ double area = 4 * pi, area2, n; while (scanf ("%lf", &n) != EOF && n >= 0) { if (n <=1) printf("0%%\n"); else { area2 = n * pi / area; printf("%.0lf%%\n", area2 * 100); } } return 0; }
In the Land of Justice the selling price of everything is xed all over the country. Nobody can buy
a thing and sell it in double price. But, that created problems for the businessmen. They left their
business and went to the production. So, after some days everybody was in production and nobody
in business. And the people didn't get their necessary things though the country was self-sufficient in
every sector.
The government became very much anxious. But, they were intelligent enough to call the mathe-
maticians.
The mathematicians gave a solution. They suggested setting the surface area of an object as its
selling-unit instead of its volume. Actually the clever mathematicians were very much interested to
establish their own business.
Now, the government asks the programmers to build the software that would calculate the pro t
things.
Here your job is to calculate the business pro t for a solid sphere. A businessman buys a complete
sphere and to maximize his pro t he divides it in
n
equal parts. All cut should go through the axis of
the sphere. And every part should look like the picture below:
Input
You are given a sequence of integers
N
(0
<N<
2
31
), indicating the numbers of parts of the sphere.
The input le is terminated with a negative number. This number should not be processed.
Output
Calculate the pro t over the sold pieces. The result should be in percentage and rounded to the nearest
integer.
SampleInput
2
2
-1
SampleOutput
50%
50%
相关文章推荐
- 《FLASH CC 2015 CANVAS 中文教程》——2、基本的交互(点击、触摸)事件
- POJ 1017 Packets
- SSAS处理时“找不到属性键”的解决办法 (转载)
- PowerBuilder中使用JDBC连接MYSQL 无法使用COUNT(*) MAX() 函数的处理
- BAT批处理文件语法
- Method about connect to Netezza using ODBC in SAS EG
- Linux - 系统常用命令
- FFMPEG timestamp conception and Unit Conversion
- HDUOJ_1869(六度分离)(dijkstra)
- poj 3468 线段树成段增减+区间求和
- Android Material Design之Toolbar与Palette实践
- c多线程学习
- Linux - Linux系统目录架构
- Android播放在线音乐文件
- Struts2 result 集类型列表
- JQuery中全选与反选的
- Android播放在线音乐文件
- 【剑指offer】直扑克
- Linux - 文件基本操作管理
- aauto学习系列之<1>