poj3077

这题需要进行许多次四舍五入,得到最终结果,四舍五入的方法是(int)(x + 0.5)

View Code
#include <iostream>
#include
<cstdlib>
#include
<cstring>
#include
<cstdio>
using namespace std;

int main()
{
//freopen("D:\\t.txt", "r", stdin);
int t;
scanf(
"%d", &t);
while (t--)
{
int n, count = 0;
scanf(
"%d", &n);
double x = n;
while (x >= 10)
{
x
/= 10;
x
= (int)(x + 0.5);
count
++;
}
n
= (int)x;
for (int i = 0; i < count; i++)
n
*= 10;
printf(
"%d\n", n);
}
return 0;
}

posted @ 2011-03-05 22:32  金海峰  阅读(161)  评论(0编辑  收藏  举报