hdoj-2090-算菜价(水题)

算菜价

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 16818    Accepted Submission(s): 9145

Problem Description

妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐。现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵。

Input

输入含有一些数据组,每组数据包括菜种(字串),数量(计量单位不论,一律为double型数)和单价(double型数,表示人民币元数),因此,每组数据的菜价就是数量乘上单价啊。菜种、数量和单价之间都有空格隔开的。

Output

支付菜价的时候,由于最小支付单位是角,所以总是在支付的时候采用四舍五入的方法把分头去掉。最后,请输出一个精度为角的菜价总量。

Sample Input

青菜 1  2
罗卜 2  1.5
鸡腿 2  4.2

Sample Output

13.4

解题思路

这道题之所以不知道如何下手,是因为根本没告诉大家输入结束标志是什么,这种情况下,直接按照!=EOF走就行。

还有就是题目意思应该是只付一次总价,所以最后四舍五入就好。

代码

#include<stdio.h>
char nam[110];
int main()
{
	double num,mon;
	double sum=0;
	while(scanf("%s%lf%lf",nam,&num,&mon)!=EOF)
	{
		sum+=num*mon;
	}
	printf("%.1lf\n",sum);
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-29 12:23:32

hdoj-2090-算菜价(水题)的相关文章

HDU 2090 算菜价 --- 水题

/* HDU 2090 算菜价 --- 水题 */ #include <cstdio> int main() { char s[105]; double a, b, sum = 0; while (scanf("%s", s)==1){ scanf("%lf%lf", &a, &b); a *= b; sum += a; } printf("%.1f\n", sum); return 0; }

杭电 2090 算菜价

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2090 解题思路:将每一种菜价还有其重量相乘就可以了. 反思:其实最开始做的时候,我想的是怎样才能像题目里面那样输入数据,又没有限定输入多少组,我怎么知道在哪一组停止输入,开始输出结果,然后在VC里面像下面这样写,居然通过了------不懂----- #include<stdio.h> int main() { char c[1000]; double a,b; double sum=0; whil

hdoj 5198 Strange Class 水题

Strange Class Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5198 Description In Vivid’s school, there is a strange class(SC). In SC, the students’ names are very strange. They are in the same format: anbncn(a,

hdu 2090 算菜价

代码: #include<cstdio> #include<cmath> using namespace std; int main() { char str[100]; double p,q; double ans=0; while(~scanf("%s%lf%lf",str,&p,&q)) { ans=ans+p*q; } printf("%.1lf\n",ans);//自动会四舍五入 return 0; }

hdoj 1106 排序 【水题】

排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 35499    Accepted Submission(s): 10042 Problem Description 输入一行数字,如果我们把这行数字中的'5'都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以'0'开头,这些头部的'0'应该被忽略掉,除非这个整数就是

杭电OJ -- 2090 算菜价

#include <iostream> #include <string> #include <iomanip> using namespace std; int main() { string name_of_food; double num, unit_price; double sum = 0; while (cin >> name_of_food) { cin >> num >> unit_price; sum += num

HDU2090 算菜价【水题】

算菜价 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 33642 Accepted Submission(s): 16551 Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input 输入含有一些数

HDOJ 2317. Nasty Hacks 模拟水题

Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3049    Accepted Submission(s): 2364 Problem Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of

水题 HDOJ 4716 A Computer Graphics Problem

题目传送门 1 /* 2 水题:看见x是十的倍数就简单了 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <string> 9 #include <cmath> 10 using namespace std; 11 12 const int MAXN = 1e4 + 10; 13