【水】hdu4493

Tutor

   Problem Description
Lilin was a student of Tonghua Normal University. She is studying at University of Chicago now. Besides studying, she worked as a tutor teaching Chinese to Americans. So, she can earn some money per month. At the end of the year, Lilin wants to know his average monthly money to decide whether continue or not. But she is not good at calculation, so she ask for your help. Please write a program to help Lilin to calculate the average money her earned per month.
 

Input
The first line contain one integer T, means the total number of cases. 
Every case will be twelve lines. Each line will contain the money she earned per month. Each number will be positive and displayed to the penny. No dollar sign will be included.
 

Output
The output will be a single number, the average of money she earned for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign without tail zero. There will be no other spaces or characters in the output.
 

Sample Input
2 100.00 489.12 12454.12 1234.10 823.05 109.20 5.27 1542.25 839.18 83.99 1295.01 1.75 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00
 

Sample Output
$1581.42 $100
期末考完了,把之前欠的题解补上!

求平均值,输出的时候要控制格式。

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
long  t;
double sum, a, re;
char s[10000];
int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);

    scanf("%d",&t);
    for (long i=1; i<=t; i++)
    {
        sum = 0;
        for (long j=1; j<=12; j++)
        {
            scanf("%lf",&a);
            sum += a;
            re = sum / 12;
        }
       // printf("%.2f\n",re);
        printf("$");
        sprintf(s, "%.2f", re);
        long l=strlen(s);
        for (long k=0; k<l-3; k++)
        {
            printf("%c",s[k]);
        }
        if ((s[l-1]!='0')||(s[l-2]!='0'))
        {
            printf("%c",s[l-3]);
            printf("%c",s[l-2]);
            if (s[l-1]!='0') printf("%c",s[l-1]);

        }
        cout<<endl;



    }

}




全部评论

相关推荐

Wy_m:只要不是能叫的上名的公司 去实习没有任何意义 不如好好沉淀自己
点赞 评论 收藏
分享
关于我大学本科四年,想了很多,但还是不知道该怎么动笔&nbsp;“大学四年,是我从懵懂少年走向职场青年的转折期。这一路跌跌撞撞,有迷茫,有遗憾,也有成长和决心。”&nbsp;大一刚进来时仍然有高中那股学习劲,经常一个人去图书馆学高等数学,但后面劲头一过便开始在宿舍开启躺平生活(现在想想那段时间真的很爽,无忧无虑)。由于大一担任班干部,所以经常要跟其他班的班干部交流,在此期间认识了隔壁班的一位女生,短发而很可爱,因为很多团建还有比赛都是我们两班一起参加的,而且我和她都是负责人,所以交集很多,后面慢慢地彼此对产生了好感,所以在大一刚开学的2个月后,我们在一起了,彼此之前都是初恋。但当时我真的是太太太直男了,对感情的想...
真烦好烦真烦:骗哥们可以,别把你自己也骗到了就行。哥们被你骗了真无所谓的,打个哈哈就过了。但希望你打完这段话后擦一下眼角,别让眼泪掉在手机屏幕上了就行。你说的这些话,哥们信一下也是没什么的。还能让你有个心里安慰,但这种话说出来骗骗兄弟就差不多得了,哥们信你一下也不会少块肉,但是你别搞得自己也当真了就行。哥们被你骗一下是真无所谓的,兄弟笑笑也就过去了。真不是哥们想要破你防,你擦擦眼泪好好想想,除了兄弟谁还会信你这些话?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务