Problem B: 成绩排序
2017-05-06 19:04
239 查看
Home | Web Board | ProblemSet | Standing | Status | Statistics |
Problem B: 成绩排序
Time Limit: 1 Sec Memory Limit:128 MB
Submit: 1579 Solved: 1259
[Submit][Status][Web
Board]
Description
定义Student类:1. 数据成员string name和int score表示一个学生的姓名、成绩。
2. 无参构造函数。
3. void setStudent(string,int)方法,用于设置一个学生的属性值。
4. 重载>(大于运算符)。Student类的对象A和B的大小关系,A>B定义为A.score>B.score,或者A.score=B.score但A.name<B.name。
5.重载运算符<<用于输出学生信息:先输出成绩再输出姓名,中间用一个空格隔开。
Input
分多行。第一个M>0表示有M个学生信息。之后有M行,每一行是一个学生信息。第一部分是学生姓名,第二部分是学生成绩。
Output
输出为M行,按照从大到小的顺序依次输出每个学生的成绩、姓名。假定不存在重名的学生。Sample Input
5Tom 98Jack 97Mary 98Sherry 99Dock 97Sample Output
99 Sherry98 Mary98 Tom97 Dock97 JackHINT
string类有个方法:int compare(const string &s) const;用于比较当前字符串和s的大小,其原理等同于C语言的库函数strcmp。Append Code
append.cc,[Submit][Status][Web
Board]
한국어< 中文 فارسی English ไทย
All Copyright Reserved 2010-2011
SDUSTOJ TEAM
GPL2.0 2003-2011
HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin
#include <iostream> #include <string> using namespace std; class Student { public: void setStudent(string n,int s) { name = n; score = s; } public: Student(){} private: string name; int score; public: bool operator > (const Student s) { if(score > s.score) return true; if(score == s.score && name < s.name) return true; return false; } friend ostream &operator <<(ostream & os, const Student & s)\ { os << s.score << " " << s.name ; return os; } }; int main() { int cases; string name; int score; cin>>cases; Student students[cases], temp; for (int i = 0; i < cases; i++) { cin>>name>>score; students[i].setStudent(name, score); } for (int i = 0; i < cases; i++) { for (int j = 0; j < cases - i - 1; j++) { if (!(students[j] > students[j + 1])) { temp = students[j]; students[j] = students[j + 1]; students[j + 1] = temp; } } } for (int i = 0; i < cases; i++) cout<<students[i]<<endl; return 0; }
相关文章推荐
- 1478 Problem A 总成绩排序(结构体专题)——软四课堂小测试2——2017-12-22
- Problem E: 成绩排序
- 学生成绩排序
- C/C++动态自定义结构体数组实例锻炼-学生成绩排序
- 九度OJ-1061:成绩排序
- java小练习(6)--排序 problem
- 九度OJ 1061:成绩排序 (排序)
- “黑马程序员”声明类Student,包含3个成员变量:name、age、score,创建5个对象装入TreeSet,按照成绩排序输出结果(考虑成绩相同的问题)
- 有5名学生保存在结构体数组中,编程按学生的成绩升序排序,按学生的姓名降序排序,按年龄从低到高排序, 成绩, 年龄
- 题目1061:成绩排序
- 题目1061:成绩排序
- 黑马程序员:学生类按成绩排序问题
- 《第十六周实验报告任务2——学生成绩排序》
- 从键盘上输入以下的数据:"TOM:89|JERRY:90|TONY:95",数据格式为“姓名:成绩|姓名:成绩|姓名:成绩”,对输入的内容按成绩进行排序,并将结果按成绩由高到低排序。
- 华为OJ训练之0029-170109-成绩排序
- Problem G 排序练习00(难度5)
- FZU Problem 2212 Super Mobile Charger(贪心,排序)——第六届福建省大学生程序设计竞赛-重现赛
- 奇怪的排序 http://acm.nyist.net/JudgeOnline/problem.php?pid=540
- 第十四周项目2.1带姓名的成绩单按成绩排序输出
- http://acm.hdu.edu.cn/showproblem.php?pid=1106&&排序