problem url: http://acm.timus.ru/problem.aspx?space=1&num=1001
Use static Array to hold all the square root values and print them all:
the AC result is not so good: 0.42s and 12xxKB, maybe I should implement the sqrt myself?
#include
<
cstdio
>
#include < iostream >
#include < cmath >
using namespace std;
#define MAXNUM 700000
double dList[MAXNUM];
void main()
{
int i = 0 ;
double dCur = 0.0 ;
while (scanf( " %lf " , & dCur) != EOF)
{
dList[i] = sqrt(dCur);
++ i;
}
while (i > 0 )
{
printf( " %.4f " , dList[i - 1 ]);
-- i;
}
}
#include < iostream >
#include < cmath >
using namespace std;
#define MAXNUM 700000
double dList[MAXNUM];
void main()
{
int i = 0 ;
double dCur = 0.0 ;
while (scanf( " %lf " , & dCur) != EOF)
{
dList[i] = sqrt(dCur);
++ i;
}
while (i > 0 )
{
printf( " %.4f " , dList[i - 1 ]);
-- i;
}
}
本文介绍了一个使用静态数组存储并计算输入数值平方根的C++程序示例。该程序读取一系列浮点数,并使用标准库函数`sqrt`计算每个数的平方根,最后将结果按接收顺序逆序输出。
419





