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 ...
随机推荐
- Oracle-01-数据库分类/oracle sql*plus常用命令
一.数据库分类 一.数据库分类1.小型数据库:access.foxbase2.中型数据库:informix.sql server.mysql3.大型数据库:sybase.db2.oracle 二.项目 ...
- vue入门: 实现选中并显示修改功能
1.实现功能 2.工具 vue 3.代码 <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- cookie与session的区别,你真的明白吗?
当我们访问网页时,http是属于无状态的,为什么呢?接下来由我慢慢讲解,在cookie的到来之前,你第一次访问页面的时候和最后一次访问页面服务器是不知道的,不知道那一次访问的页面是你.当用户登录的时候 ...
- string类中字符的大小写转换
今天做一道题,要用string类,涉及大小写转换,查看了C++文档,string类没有提供这样的方法,只好自己写. 之后是想到一个比较笨的方法,我把string当成一个容器,然后用迭代器一个一个来替换 ...
- ABAP术语-Fiscal Year
Fiscal Year 原文:http://www.cnblogs.com/qiangsheng/archive/2008/02/02/1062109.html Generally a period ...
- 在Windows系统上使用压缩归档文件安装MySQL流程
最近需要做个小小的验证实验,需要安装MySQL,网上一搜发现教程繁多,bug也多,所以直接把官网的流程翻译过来,注意是压缩文件,不是安装版的,解压直接能用的,下面直接把流程贴过来: 使用压缩文档安装在 ...
- xpath技术解析xm文件(php)
1.结合php dom技术的学习,得出一个结论:php dom技术可以跨层取出节点,但是不能保持层次关系,使用xpath可以很好地解决问题. *** xpath技术的核心思想:迅速简洁的定位你需要查找 ...
- jquery点击li 获取当前父节点所在类的索引
jquery点击li 获取当前父节点所在类的索引 $('.jbcz').find('.content li').click(function(){ //alert($('.jbcz').find('. ...
- 【基于不同设备厂商在处理vlan之间通信配置例子】
H3C: Dot1q子接口实现vlan之间的通信 一:根据项目需求搭建好拓扑图如下: 二:配置 HUAWEI: CISCO
- PHP生成一个六位数的邀请码
PHP生成一个六位数的邀请码 $unique_no = substr(base_convert(md5(uniqid(md5(microtime(true)),true)), 16, 10), 0, ...