题目:http://acm.hdu.edu.cn/showproblem.php?pid=4493

给你十二个月的工资,算平均数,保留两位,去除末尾的0

使用暴力解决,嘻嘻,但是这题主要是在进位这个地方要处理好,由于

要去除末尾0,采用一个数组来保存小数点后面的数,

当要进位时,从未到头查看是否是要进位

最后将整数部分输出,然后输出小数部分(满足要求的小数位输出)

代码:

#include <stdio.h>

int main()
{
double x,sum;
int t,i,j;
scanf("%d",&t);
while(t--)
{
i = 12;
sum = 0.0;
while(i--)
{
scanf("%lf",&x);
sum += x;
}
sum = 1.0*sum / 12*1.0; if(sum - (int)(sum) < 0.0000001)
printf("$%d\n",(int)sum);
else
{
int w = (int)sum;
int t1 = 0;
int a[4] = {0,0,0,0};
double k = sum - (int)sum;
while(1)
{
if(t1 == 3) break;
k *= 10*1.0; a[t1++] = (int)k % 10;
}
int tt = 0;
if(a[2] > 4)
{
if(a[1]+1 > 9)
{
tt = (a[1] + 1) / 10;
a[1] = (a[1] + 1) % 10;
if(a[0] + tt > 9)
{
tt = (a[0] + tt) / 10;
a[0] += 1 % 10;
w += tt;
}
else
a[0] += tt;
}
else
a[1] += 1;
}
i = 2;
while(i--)
if(a[i]) break;
printf("$%d",w);
if(i >= 0)
printf(".");
for(j = 0; j <= i; j++)
printf("%d",a[j]);
printf("\n");
}
}
return 0;
}

hdu 4493 Tutor的更多相关文章

  1. hdu 4493 Tutor 水题

    Tutor Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 D ...

  2. HDU 4493 Tutor 水题的收获。。

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...

  3. HDU 4493 Tutor (水题)

    Tutor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submi ...

  4. HDU 4493 Tutor(精度处理)

    题目 #include<stdio.h> int main() { int t; double a,s; scanf("%d",&t); while(t--) ...

  5. HDU 4493 Tutor (控制精度)

    题意:给定12个数,求平均数. 析:这个题就是精度控制问题,如果控制精度,最好的办法就是用整型了. 代码如下: #include <cstdio> #include <string& ...

  6. Hdu 4493

    题目链接 注意四舍五入,保留到小数点后两位(如果存在的话). 附上代码: /************************************************************** ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. iphone--有关日历中NSDateFormatter中英文

    在使用日历使用中,获取星期的时候 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFo ...

  2. MAVEN入门(一)

    一.Maven的基本概念 Maven是跨平台的项目管理工具.主要服务于基于Java平台的项目构建,依赖管理和项目信息管理. 1.1.项目构建 项目构建过程包括[清理项目]→[编译项目]→[测试项目]→ ...

  3. BST的删除

    #include<iostream> #include<math.h> #include<stdio.h> #include<stdlib.h> #in ...

  4. struts2日常

    更新struuts2 的action后不能马上反应,要重启服务器才可以,加上 <constant name="struts.devMode" value="true ...

  5. js监听input等表单输入框的变化事件oninput

    js监听input等表单输入框的变化事件oninput,手机页面开发中使用到文本框textarea输入字符监听文本框变化计算还可以输入多少字符,如果使用onkeyup的话是无法监听到输入法输入的文本变 ...

  6. SQLSERVER 使用WITH函数查找时间点最大数据行

      --表结构及数据: DTIME TYPE MONEY 2015-10-14 13:50:35.000 shopping 20 2015-10-21 13:51:24.000 shopping 40 ...

  7. Prepare Python environment and install selenium.

    1, Install python and selenium. I use python 3.5, the following is the example 1.)    Python downloa ...

  8. Myeclipse普通工程转为Maven工程

    在SVN导出的Maven项目,或以前不是用Maven管理的项目想要转换成Maven项目,但Myeclipse中右键Configure 找不到(eclipse可行)Convert to maven pr ...

  9. Delphi中的Rtti函数

    TTypeKind,类型类别,tkclass,tkinteger,tkstring等.类,属性都是一种类型. ttypedata,是一个record包括ttypekind.是一个类的描述.TTypeK ...

  10. 柯南君:看大数据时代下的IT架构(9)消息队列之RabbitMQ--案例(RPC起航)

    二.Remote procedure call (RPC)(using the Java client) 三.Client interface(客户端接口) 为了展示一个RPC服务是如何使用的,我们将 ...