当前位置:网站首页>PTA:6-33 学生排名表(析构函数)
PTA:6-33 学生排名表(析构函数)
2022-06-23 03:47:00 【Sy_Faker】
现在输入一批学生(人数大于0且不超过100)的名次和他们的姓名。要求按名次输出每个人的排名。
输入格式:每行为一个学生的信息,共两项,第一项为排名(为正整数,且任意两名学生的排名均不同),第二项为学生姓名。当输入-1时,表示输入结束。
输出格式:按名次输出学生姓名,每行一个。
函数接口定义:
main函数的一部分。
裁判测试程序样例:
#include <iostream>
#include <string>
using namespace std;
class Student{
int rank;
string name;
public:
int getRank(){
return rank; }
Student(string name, int rank):name(name), rank(rank){
}
~Student(){
cout<<name<<endl;}
};
int main(){
int rank, count=0;
const int SIZE=100;
Student *pS[SIZE];
string name;
cin>>rank;
while(count<SIZE && rank>0){
cin>>name;
pS[count++]= new Student(name, rank);
cin>>rank;
}
/* 请在这里填写答案 */
return 0;
}
输入样例:
1 Jack
5 Peter
2 Alice
6 Kate
52 Mike
-1
输出样例:
Jack
Alice
Peter
Kate
Mike
我用冒泡做的:
Student *temp;
for(int i=0;i<count;i++)
{
for(int j=i+1;j<count;j++)
{
if(pS[i]->getRank()>pS[j]->getRank())
{
temp=pS[i];
pS[i]=pS[j];
pS[j]=temp;
}
}
}
for(int i=0;i<count;i++)
delete pS[i];
边栏推荐
- Software project management 8.4 Software project quality plan
- Xiaojinwei, chairman of Chenglian Technology: implement the national strategy of data economy and lead the development of new consumption in the digital era!
- Efficient remote office experience | community essay solicitation
- Form development mode
- 怎么使用Shell脚本实现监测文件变化
- Bug STM32 advanced timer (haha, to tell you the truth, the hardware timer can't reflect its strength. In fact, I want to send the kernel timer. Just think about it. Take your time)
- APM 工具 SkyWalking 是什么
- Adobe international certification 𞓜 how IIT Madras brings efficiency and accessibility to scholars through Adobe e Acrobat
- Software development in 2022: five realities CIOs should know
- 如何保证应用程序的安全性
猜你喜欢

摆烂LuoGu刷题记

京东云分布式数据库StarDB荣获中国信通院 “稳定性实践先锋”

Differences between MyISAM and InnoDB of MySQL storage engine

Software project management 8.4 Software project quality plan

移动端城市列表排序js插件vercitylist.js

AI video cloud vs narrowband HD, who is the favorite in the video Era

深度学习 TensorFlow入门

IDEA-导入模块

如何处理大体积 XLSX/CSV/TXT 文件?

最新编程语言排行榜
随机推荐
Black horse PostgreSQL, why is it black in the end
PTA:7-31 期刊收费
理想汽车×OceanBase:当造车新势力遇上数据库新势力
How to solve the problem that the web page fails to log in after the easycvr service is started?
虫子 日期类 上 太子语言
How to process large volume xlsx/csv/txt files?
Ideal car × Oceanbase: when new forces of car building meet new forces of database
Software project management 8.4 Software project quality plan
bubble sort
在 KubeSphere 上部署 Apache Pulsar
How MySQL deletes a row of data in a table
众昂矿业:新能源新材料产业链对萤石需求大增
What is metadata
What is the difference between redistemplate and CacheManager operation redis
Review the SQL row column conversion, and the performance has been improved
深度学习 TensorFlow入门
What is the APM tool skywalking
【深度学习】深度学习推理框架 TensorRT MNN OpenVINO ONNXRuntime
leetcode 91. Decode Ways 解码方法(中等)
支持在 Kubernetes 运行,添加多种连接器,SeaTunnel 2.1.2 版本正式发布!