vector sort AND 友元
2024-08-27 23:10:51
# include<iostream>
# include<string>
# include<algorithm>
# include<stdio.h>
# include<vector>
using namespace std;
struct student
{
int hao,h,w;
string name;
}stu;
bool LessSort(student a,student b) { return (a.hao<b.hao); }
int main()
{
int n,xh,xm,he,we;
cin>>n;
vector<student> v;
for(int i=;i<n;i++)
{
cin>>stu.hao>>stu.name>>stu.h>>stu.w;
v.push_back(stu);
}
sort(v.begin(),v.end(),LessSort);
int count=,maxh,maxw,flag=;
string maxname;
for(int i=;i<n;i=i+)
{
if(i==)
{
maxh = v[i].h;
maxname = v[i].name;
maxw = v[i].w;
}
else
{
if(v[i].hao==v[i-].hao)
{
if(v[i].h>v[i-].h)
{
maxh = v[i].h;
maxname = v[i].name;
maxw = v[i].w;
}
}
else
{
printf("%06d ",v[i-].hao);
cout<<maxname<<" "<<maxh<<" "<<maxw<<endl;
maxh = v[i].h;
maxname = v[i].name;
maxw = v[i].w;
if(i==n-)
{
printf("%06d ",v[i-].hao);
cout<<maxname<<" "<<maxh<<" "<<maxw<<endl;
}
}
}
}
return ;
}
#include<iostream>
using namespace std;
class Student
{
public:
Student()
{
number=;
name;
mark=;
}
void set_student();
void show_student();
friend void find(Student stu[],int q);
private:
int number;
char name[];
int mark;
};
void Student::set_student()
{
cin>>number;
cin>>name;
cin>>mark;
}
void Student::show_student()
{
cout<<number<<' '<<name<<' '<<mark<<endl;
}
void find(Student stu[],int q)
{
int min=,w;
for(int i=;i<q;i++)
{
if(stu[i].mark<min)
{
w=i;
min=stu[i].mark;
}
}
stu[w].show_student();
}
int main()
{
int n;
Student stu[];
while(cin>>n)
{
if(n==)break;
for(int i=;i<n;i++)
{
stu[i].set_student();
}
find(stu,n);
}
return ;
}
最新文章
- python之路二十一
- [经验] Win7减肥攻略(删文件不删功能、简化优化系统不简优化性能)
- Git服务器搭建及配置
- C#5.0 特性
- poj 3841 Double Queue (AVL树入门)
- 在树莓派上使用ss和iptables实现fq功能
- 使用ttXactAdmin、ttSQLCmdCacheInfo、ttSQLCmdQueryPlan获取SQL相关具体信息[TimesTen运维]
- DOM遍历 - 后代
- Java 三大特性
- IO代码记忆
- 【.NETCore开源】开弓没有回头箭
- mpvue——引入vant_weapp组件
- MVC 使用缓存
- 我的django2
- #WEB安全基础 : HTML/CSS | 0x1初识CSS
- python----函数的动态传参
- servlet 请求乱码解决
- 用prop还是attr
- Highcharts.Chart
- Java从入门到精通全套教程免费分享