zoukankan      html  css  js  c++  java
  • Hdu 4493

    题目链接

    注意四舍五入,保留到小数点后两位(如果存在的话)。

    附上代码:

     1 /*************************************************************************
     2     > File Name: 4493.cpp
     3     > Author: Stomach_ache
     4     > Mail: sudaweitong@gmail.com
     5     > Created Time: 2014年05月19日 星期一 22时39分19秒
     6     > Propose: 
     7  ************************************************************************/
     8 
     9 #include <cmath>
    10 #include <string>
    11 #include <cstdio>
    12 #include <fstream>
    13 #include <cstring>
    14 #include <iostream>
    15 #include <algorithm>
    16 using namespace std;
    17 
    18 int
    19 main(void) {
    20       int t;
    21     scanf("%d", &t);
    22     while (t--) {
    23           double avg = 0.0;
    24         for (int i = 0; i < 12; i++) {
    25               double a;
    26             scanf("%lf", &a);
    27             avg += a;
    28         }
    29         avg /= 12;
    30         char str[30];
    31         // 四舍五入
    32         sprintf(str, "$%.2f", avg);
    33         int len = strlen(str);
    34         if (str[len-1] == '0' && str[len-2] == '0') {
    35               str[len-3] = '';
    36         } else if (str[len-1] == '0') {
    37               str[len-1] = '';
    38         }
    39         puts(str);
    40     }
    41 
    42     return 0;
    43 }
  • 相关阅读:
    创建HttpFilter与理解多个Filter代码的执行顺序
    Filter
    JSTL
    EL
    JavaBean
    HttpSession之表单的重复提交 & 验证码
    相对路径和绝对路径
    HttpSession之简易购物车
    HttpSession
    Cookie
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3737971.html
Copyright © 2011-2022 走看看