Problem A: 求平均年龄
来源:互联网 发布:网络电视江苏卫视直播 编辑:程序博客网 时间:2024/04/29 22:46
HomeWeb BoardProblemSetStandingStatusStatistics
Submit: 1928 Solved: 1138
[Submit][Status][Web Board][Submit][Status][Web Board]
Problem A: 求平均年龄
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1928 Solved: 1138
[Submit][Status][Web Board]
Description
定义一个Persons类,用于保存若干个人的姓名(string类型)和年龄(int类型),定义其方法
void addAPerson(string,int)
用于添加1个人的信息;
double getAveAge()
用于获取所有人的平均年龄。
Input
第1行N>0表示有N个测试用例。
每个测试用例包括1个人的姓名及其年龄。
Output
所有人的平均年龄。见样例。
Sample Input
5Zhang 10Wang 20Li 30Zhao 40Zhou 50
Sample Output
30.00
HINT
Append Code
append.cc,
한국어< 中文 فارسی English ไทย
All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin
#include <iostream>#include <typeinfo>#include <iomanip>using namespace std;class Persons{private: string name; static int num; static int total; int age;public: Persons() { } ~Persons() { }public: void addAPerson(string n,int a) { num++; total +=a; age = a; } double getAveAge()const { return double(total) / double(num); }}; int Persons :: total = 0;int Persons :: num = 0;int main(){ int cases, age; string name; Persons persons; cin>>cases; for (int i = 0; i < cases; i++) { cin>>name>>age; persons.addAPerson(name, age); } cout<<setprecision(2)<<fixed<<persons.getAveAge()<<endl;}
0 0
- Problem A: 求平均年龄
- Problem A: 求平均年龄
- Problem A: 求平均年龄
- Problem B: 求平均年龄
- 1001 求平均年龄
- 01:求平均年龄
- 01:求平均年龄
- 1. 求平均年龄
- ACM java求平均年龄
- 题目1128:求平均年龄
- 题目1128:求平均年龄
- 题目1128:求平均年龄
- 题目1128:求平均年龄
- POJ 2714:求平均年龄
- 题目1128:求平均年龄
- 题目1128:求平均年龄
- 百练 2714 求平均年龄
- poj 百练 2714:求平均年龄
- 51nod1238 最小公倍数之和 V3
- 深入理解javascript原型和闭包(3)——prototype原型
- 集合类Collections.sort()的源码分析
- 移动端数据库神器-Realm 项目配置(入门一)
- Windows I/O操作
- Problem A: 求平均年龄
- Problem B: 合唱比赛开始了!
- log4j的基本配置
- Problem C: 向量的运算
- windows环境下python2.7、pycharm、numpy_mkl、scipy、sklearn、Matplotlib、jupyter完整安装教程
- 如何快速构建用户画像?
- 守护进程
- Problem D: 模板是个好东西
- Codeforces Round #373 (Div. 2) A. Vitya in the Countryside —— 基础题