我希望你是我独家记忆

一段永远封存的记忆,随风而去
posts - 263, comments - 31, trackbacks - 0, articles - 3
   :: 首页 :: 新随笔 ::  :: 聚合  :: 管理

P3077——四舍五入

Posted on 2008-09-02 11:36 Hero 阅读(119) 评论(0)  编辑 收藏 引用 所属分类: 代码如诗--ACM
 1 //3077 Accepted 312K 0MS G++ 684B PKU
 2 
 3 //利用+0.5来进行四舍五入
 4 
 5 #include <stdio.h>
 6 #include <stdlib.h>
 7 #include <string.h>
 8 
 9 int inn ;
10 int inval ;
11 
12 int fpow( int a, int b )
13 {
14     int reval = 1 ;
15 
16     forint i=1; i<=b; i++ ) reval = reval * a ;
17 
18     return reval ;
19 }
20 
21 void process()
22 {
23     double out ; int pow ;
24     forint i=1; i<=inn; i++ ) 
25     {
26         scanf( "%d"&inval ) ; pow = 0 ; out = inval * 1.0 ;
27         while( inval > 9  )
28         {
29             out = out / 10 ; pow++ ; 
30             inval = (int)(out+0.5) ; out = inval * 1.0 ;
31         }
32 
33         printf( "%d\n", inval * fpow( 10, pow ) ) ;
34     }
35 }
36 
37 int main()
38 {
39     //freopen( "in.txt", "r", stdin ) ;
40 
41     while( scanf( "%d"&inn ) != EOF )
42     {
43         //input() ;
44 
45         process() ;
46 
47         //output() ;
48     }
49 
50     return 0 ;
51 }

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理