TOJ 3855.Price

题目链接:http://acm.tju.edu.cn/toj/showp3855.html


3855.    Price
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 371    Accepted Runs: 208



Ant is a student in Tianjin University. Everyday, he has to go to the restaurant in school. Recently, some other students complain about the high price of restaurant dishes. Ant is a poor man, he don't want to spend too much. Then he wants to know the total price of the dishes he wants to order before he pays for them. Now he wants to write a program to help him calculate the price. Could you help him?

Input

There are several test case in the input file. For each test case, the first line contains two integer n and m, seperated by a single space. n is the number of all the dishes and m is the number of the dishes that Ant wants to order. Then n ( 0 < n ≤ 100) lines follows and each line contains one string si and an real number ai. The string siis the name of the i-th dish and the real number ai is the price of the i-th dish. The length of string si is less than 10. The next m following lines describe the dishes which Ant wants to order and each of them contains a string which is the name of dish. Every dish is calculated only once.

Output

For each test case, output a real number which is the total price in a line. The total price should be printed with two digits to the right of the decimal point.

Sample Input

3 2
rice 0.5
egg 2.0
meat 5.0
meat
rice

Sample Output

5.50



Source: TJU 2012 Team Selection
Submit   List    Runs   Forum   Statistics

水题,上代码:

#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
	string dish[101],order;
	int m,n;
	double price[101],sum;
	while(~scanf("%d%d",&n,&m)){
		sum=0;
		for(int i=0;i<n;i++)
		{	cin>>dish[i];scanf("%lf",&price[i]);}
		for(int i=0;i<m;i++){
			cin>>order;
			for(int j=0;j<n;j++)
				if(dish[j]==order)
				 	sum+=price[j];
		}
		printf("%.2lf\n",sum);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值