map 简单用法
2007-01-30 16:41
387 查看
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
struct Data
{
Data(): cout(0),sum(0) {}
int cout;
double sum;
};
typedef map<string,Data> M;
void CollData(M &m)
{
string name;
double value;
for (;;)
{
cin>>name;
if (name == "exit")
break;
cin>>value;
m[name].sum += value;
++m[name].cout;
}
}
int main()
{
M m;
CollData(m);
map<string,Data>::const_iterator iter = m.begin();
while(iter != m.end())
{
cout<<iter->first<<" 输入次数 "<<iter->second.cout<<" 平均值为 "<<(iter->second.sum)/(iter->second.cout)<<"/n";
++iter;
}
return 0;
}
#include<map>
#include<string>
#include<algorithm>
using namespace std;
struct Data
{
Data(): cout(0),sum(0) {}
int cout;
double sum;
};
typedef map<string,Data> M;
void CollData(M &m)
{
string name;
double value;
for (;;)
{
cin>>name;
if (name == "exit")
break;
cin>>value;
m[name].sum += value;
++m[name].cout;
}
}
int main()
{
M m;
CollData(m);
map<string,Data>::const_iterator iter = m.begin();
while(iter != m.end())
{
cout<<iter->first<<" 输入次数 "<<iter->second.cout<<" 平均值为 "<<(iter->second.sum)/(iter->second.cout)<<"/n";
++iter;
}
return 0;
}
相关文章推荐
- perl grep 和 map 简单用法
- map简单用法
- 类集框架之Map简单用法
- JAVA中MAP的四种类型区别和常见的简单用法
- RxAndroid之Action,Func,map,flatmap的简单用法。
- 快速简单的了解java List,Map,List<Map>的用法
- HLG 第K大数 ----简单map用法
- uva 11991 Easy Problem from Rujia Liu?(数据结构:map的简单用法)
- codeforces 499B Lecture(map与string简单用法)
- set和map的简单用法
- code forces 4C Registration system (map 的简单用法)
- map 与 set 简单用法
- map的 简单用法
- map简单用法
- Map的简单用法入门
- GO的MAP字典简单用法示例
- javascript中关于map foreach 和reduce的用法简单叙述
- STL中map、vector的iterator的简单用法
- map的简单用法
- HDU1004 Let the Balloon Rise(map的简单用法)