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 ...
随机推荐
- CALayer简介(转)
一.简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比如一个按钮,一个文本标签,一个文本输入框,一个图标等等,这些都是UIView. 其实UIView之所以能显示在屏幕上,完全 ...
- python中and,or
在很多逻辑语句中,常常会出现and,or这两个逻辑运算符. 下面直接上代码 print(0 or None) #None ''' or比较运算符: 当or旁两边都是真的话,那么会取第一个值 当or两边 ...
- 【原创】os.chdir设置的工作路径和sys.path之间到底是个啥关系?
转载请注明出处:https://www.cnblogs.com/oceanicstar/p/9390455.html 直接放上测试后的结论(测试代码和截图过多,有兴趣的小伙伴可自己测试,未来看情况 ...
- GIt+jenkins代码自动上线
代码自动上线功能 企业部署代码上线是件比较麻烦的事情,还好我们有jenkins这个持续集成的软件可以帮助我们做很多的事情,现在我们就 来测试用jenkins推送代码上线. 我们这里测试的是一个html ...
- sql server,mysql,oracle平时用法的区别
由于工作的原因,上家公司一直使用的oracle,后来接触了的几个项目,既有使用mysql的又有使用sqlserver,自己在使用sqlserver及mysql要实现某功能时,经常要在网上找来找去,所以 ...
- 【poe设备加电配置】
开启接口的poe功能: [interface_name]: 配置poe端口的最大功率: [interface_name[: 配置poe的端口工作模式: [interface_name[: 配置poe端 ...
- PHP中有关IPV4 和IPV6地址转换以及其它一些常见问题
这里主要介绍一下 IPV4 / IPV6 在 PHP / MySQL 中如何转换.以及中间容易碰到的一些问题. 首先介绍两个函数: ip2long:将 IPV4 的字符串互联网协议转换成长整型数字 i ...
- redis之哨兵(Sentinel)
Redis-Sentinel是redis官方推荐的高可用性解决方案,当用redis作master-slave的高可用时,如果master本身宕机,redis本身或者客户端都没有实现主从切换的功能. 而 ...
- Windows10 快捷键
windows 10快捷键: F1 打开帮助 F2 重命名 F3 打开搜索文件和文件夹 F4 打开地址栏常用的地址 F5 刷新 F11 全屏 选择文件和内容: shift + 上下左右键选择连续的 ...
- Scala继承
override重写 为什么要用override关键字?因为这样更清楚,不容易出错,比如打错字了,就没覆盖成功,但是不会报错 override可以覆盖feild和method class Person ...