Problem : STL——水果店
来源:互联网 发布:ntp服务器软件 编辑:程序博客网 时间:2024/04/28 15:06
话不多说,先上题目为敬~
Problem K: STL——水果店
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 4265 Solved: 1796
[Submit][Status][Web Board]
Description
小明经营着一个不大的水果店.现在他想要一份水果销售情况的明细表,这样就可以很容易掌握所有水果的销售情况了.
Input
输入包含多组数据.每组测试数据的第一行是一个整数M(0<M<=100),表示有M次成功的交易.其后有M行数据,每行表示一次交易,由水果名称(长度不超过80)和交易的水果数目(正整数,不超过100)组成.
Output
对于每一组测试数据,请你输出一份排版格式正确(请分析样本输出)的水果销售情况明细表.这份明细表包括所有水果的名称和其销售总数的信息.按照水果名称排序。格式见样例!
Sample Input
3apple 3sugarcane 1pineapple 3
Sample Output
apple:3pineapple:3sugarcane:1
HINT
用STL的map容易实现
Append Code
这道题目依然是map的应用。思考map中的函数如何在题目中进行应用。
#include <iostream>#include <map> using namespace std; int main(){ int n; while(cin>>n) { map<string,int>m; while(n--) { string s; int num; cin>>s>>num; m[s] += num; } map<string,int> ::iterator it; for(it=m.begin();it != m.end();it++) { cout<<it->first<<":"<<it->second<<endl; } m.clear(); } return 0;}
阅读全文
0 0
- Problem : STL——水果店
- Problem K: STL——水果店
- Problem K: STL——水果店
- Problem A: STL—水果店(map见解及实例应用)
- Problem D: 水果店
- Problem : STL——字典
- Problem E: STL——括号匹配
- Problem F: STL——集合运算
- Problem I: STL——括号匹配
- Problem H: STL——表达式求值
- Problem J: STL——字典
- Problem L: STL——字符串排序
- Problem M: STL——整理唱片
- Problem E: STL——管道一
- Problem D: STL——管道二
- Problem B: STL——管道一
- Problem A: STL——管道二
- Problem A: STL——管道二
- CentOS7搭建LNMP(Linux+Nginx+MySQL+PHP) 环境
- intellij+scala+maven+git
- android下调试3G/4G之Ril库分析
- 嵌入式系统Linux内核开发工程师必须掌握的三十道题
- pycharm 2016.3.2注册码
- Problem : STL——水果店
- 70
- rabbitmq 交换模式-Headers
- mysql通过Binlog恢复数据到sql文件实战
- 语音信号滤波去噪——使用FLATTOPWIN设计的FIR滤波器
- 抢救
- My.Life.Story.v1.0-TE\
- MPI编程--求最大值
- 关于Xcode"this class is not key value coding-compliant for the key" 的错误问题