当前位置:网站首页>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];
边栏推荐
- Mysql, field problem
- Common events for elements
- The tax software exits when it detects that it is a virtual machine. How to solve this problem?
- [tcapulusdb knowledge base] [list table] example code for deleting the data at the specified location in the list
- AI video cloud vs narrowband HD, who is the favorite in the video Era
- 元素的常用事件
- Differences between MyISAM and InnoDB of MySQL storage engine
- Introduction to deep learning
- x64dbg 基本使用技巧
- 基于FPGA的VGA协议实现
猜你喜欢

理想汽车×OceanBase:当造车新势力遇上数据库新势力

Pytorch---Pytorch进行自定义Dataset

mysql如何删除表的一行数据

svg d3. JS generate tree tree view

JD cloud distributed database stardb won the "stability practice pioneer" of China Academy of information technology

【深度学习】深度学习推理框架 TensorRT MNN OpenVINO ONNXRuntime

Latest programming language rankings

8 key indicators to measure technology debt in 2022

深度学习 简介

Pytorch---使用Pytorch的预训练模型实现四种天气分类问题
随机推荐
Pyspark, paid for data cleaning and uploading to the database
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)
Web page dynamic and static separation based on haproxy
仿360桌面悬浮球插件
Preface
靜態查找錶和靜態查找錶
Online JSON to CSharp (c) class tool
photoshop PS 查看像素坐标、像素颜色、像素HSB颜色
[Shangshui Shuo series] day three - preview4
JD cloud distributed database stardb won the "stability practice pioneer" of China Academy of information technology
Prince language under insect date category
Pytorch---使用Pytorch的预训练模型实现四种天气分类问题
P1347 排序(topo)
Pytorch---Pytorch进行自定义Dataset
Flutter怎么实现不同缩放动画效果
基于HAProxy实现网页动静分离
【二叉树进阶】AVLTree - 平衡二叉搜索树
怎么使用Shell脚本实现监测文件变化
Create a desktop shortcut to your appimage
PTA: Simulation Implementation of 7-86 set (function template)