1001: The Sum Problem
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
3s | 8192K | 16748 | 3298 | Standard |
In this problem, you are to write a program to calculate the sum of inputs. The input file consists exactly one case and you should print your result on a single line.
Input Specification
The input consists of N lines, each of which contains one number.
Output Speciication
For the numbers your program reads, your program should print the sum of them to the stdout on a single line.Please keep 2 digits after decimal point.
Sample Input
1 2 3.59 4
Sample Output
10.59
Hint
本题目考察输出格式问题。要求小数点后保留两位。使用C语言时,类似如下代码:
printf("%.2lf\n", s);使用C++的流库时,代码样例如下:
cout.setf(ios::fixed); cout.precision(2);
又:以前的用户可以看出,本题经过修改。原来的题目有问题,详细解释如下:
原来的意思是将输出的浮点数的末尾的0都去掉,假如结果为12.0000,输出'12';假如结果为12.8900,输出"12.89"。
这项任务用流库可以简单实现(但不完全对),如下设置:
cout.setf(ios::floatfield, ios::scientific); cout.precision(15);另外,第一句话是可以不用的,也可以简化为cout.setf(ios::floatfield); 因为这是默认设置。
但这不是标准答案,因为这样做启用了科学计数法,当要输出的数值足够大时,将输出类似1.23e15的形式。
如果使用C语言的stdio,无法直接实现该要求
因此,最好的做法是,使用定点表示法,将结果输出到一个字符串中,然后将尾部的0抹掉。C语言示例代码如下:
sprintf(str,"%lf",s); for(i=0;str[i]!='0';i++) printf("%c",str[i]); printf("\n");
Submit / Problem List / Status / Discuss