vector sort AND 友元
# 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 ;
}
vector sort AND 友元的更多相关文章
- [转] C++的STL库,vector sort排序时间复杂度 及常见容器比较
http://www.169it.com/article/3215620760.html http://www.cnblogs.com/sharpfeng/archive/2012/09/18/269 ...
- STL vector+sort排序和multiset/multimap排序比较
由 www.169it.com 搜集整理 在C++的STL库中,要实现排序可以通过将所有元素保存到vector中,然后通过sort算法来排序,也可以通过multimap实现在插入元素的时候进行排序.在 ...
- 【转】 std list/vector sort 排序
[转自]http://blog.csdn.net/marising/article/details/4567531 网上江湖郎中和蒙古大夫很多,因此,此类帖子也很多.关于排序,我还真没研究过,看了江湖 ...
- 发现一个c++ vector sort的bug
在开发中遇到一个非常诡异的问题:我用vector存储了一组数据,然后调用sort方法,利用自定义的排序函数进行排序,但是一直都会段错误,在排序函数中打印参加排序的值,发现有空值,而且每次都跟同一个数据 ...
- [LeetCode] 56. Merge Intervals(vector sort)
/** * Definition for an interval. * struct Interval { * int start; * int end; * Interval() : start(0 ...
- std list/vector sort 自定义类的排序就是这么简单
所以,自己研究了一下,如下:三种方式都可以,如重写<,()和写比较函数compare_index.但是要注意对象和对象指针的排序区别. 1.容器中是对象时,用操作符<或者比较函数,比较函数 ...
- c++ 的vector sort遇到栈错误
在做pat乙级1082 射击比赛时 遇到了sort 段错误. 题目链接:https://www.patest.cn/contests/pat-b-practise/1082 感觉写的没啥毛病 但就是段 ...
- c++排序相关的参数“cmp“的用法及理解
对sort函数(需要algorithm头文件),它的cmp可以是"函数",也可以是"对象" bool myfunction (int i,int j) { re ...
- STL练习题续
//zjnu 1399 //sort 数组可用//vector sort(vector) #include<iostream> #include<algorithm> usin ...
随机推荐
- iOS之UITextField输入错误的震动动画
//左右震动效果 - (void)shake:(UIView *)view { CGRect frame = view.frame; CAKeyframeAnimation *shakeAnimati ...
- flask中的CBV和FBV
flask中CBV使用 from flask import Flask, views app = Flask(__name__) class Login(views.MethodView): meth ...
- 你不知道的javaScript笔记(3)
对象 对象可以通过两种形式定义: 声明形式和构造形式 声明形式语法: var myObj = {key:value} 构造形式语法: var myObj = new Object(); myObj.k ...
- Ionic的项目结构(angluar js)
Hybird HTML5 App(移动应用开发)之3.Ionic的项目结构 前面使用命令ionic start myapp下载了默认的Ionic应用程序,下面我们打开应用程序项目,来分析一下Ionic ...
- 搭建简单的hadoop集群(译文)
本文翻译翻译自http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-common/ClusterSetup.html 具体的实 ...
- 构建高可靠hadoop集群之5-服务级别授权
本人翻译自: http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-common/ServiceLevelAuth.html ...
- 【原创】展开二层嵌套列表(或pd.Series)的几种方法效率对比
转载请注明出处:https://www.cnblogs.com/oceanicstar/p/10248763.html ★二层嵌套列表(或以列表为元素的pd.Series)有以下几种展开方式 (1)列 ...
- Windows登录密码明文获取器
软件原理:本软件根据开源工具mimikatz2.0 修改!软件能直接读取系统明文密码! 支持32位.64位系统 win xp/vista/7/8/8.1 本机win10专业版测试不能获取,虚拟机win ...
- 配置p6spyLog输出sql完整日志
第一步: 配置maven <dependency> <groupid>p6spy</groupid> <artifactid>p6spy< ...
- java 时间转换去杠
public static String minusHyphen(String dateParam){ if(dateParam ==null) return null; if(dateParam.i ...