C++数据结构-结构体

学生信息

http://oj.61coding.cn/problem.php?cid=1028&pid=0

#include<bits/stdc++.h>
using namespace std;
struct student{
string name;
char sex;
int age;
double weight;
};
int main(){
student stu;
cin >> stu.name >> stu.sex >> stu.age >> stu.weight;
cout << stu.name <<" "<< stu.sex <<" "<< stu.age <<" ";
cout << fixed << setprecision(1) << stu.weight << endl;
return 0;
}

年龄排序

http://oj.61coding.cn/problem.php?cid=1028&pid=1

#include<bits/stdc++.h>
using namespace std;
struct stu{
string name;
string sex;
int year,month;
};
const int MAXN = 110;
stu a[MAXN]; bool cmp(stu stu1,stu stu2){
if(stu1.year!=stu2.year){
return stu1.year>stu2.year;
}
return stu1.month>stu2.month;
}
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i].name >> a[i].sex >> a[i].year >> a[i].month;
sort(a+1,a+n+1,cmp);
for(int i = 1; i <= n; i++){
cout<< a[i].name <<" "<< a[i].sex<<" ";
cout<< a[i].year <<" "<< a[i].month<<endl;
}
return 0;
}

猴子选大王

#include<bits/stdc++.h>
using namespace std;
int m,n;
bool a[101];
int main(){
cin>>m>>n;
int num=0,w=m,t=0;
while(m>1){
t++;
if(a[t]==false){
num++;
}
if(num==n){
a[t]=true;
num=0;
m--;
}
if(t==w){
t=0;
}
}
for(int i=1;i<=w;i++){
if(a[i]==false){
cout<<i;
break;
}
}
}
#include<bits/stdc++.h>
using namespace std;
int m,n;
bool a[1001];
int main(){
cin>>m>>n;
int num=0,w=m,t=0;
int nn=n%m;
if(nn==0){
nn=m;
}while(m>1){
t++;
if(a[t]==false){
num++;
} if(num==nn){
a[t]=true;
num=0;
m--;
nn=n%m;
if(nn==0){
nn=m;
}

}
if(t==w){
t=0;
}
}
for(int i=1;i<=w;i++){
if(a[i]==false){
cout<<i;
break;
}
}
}
#include<bits/stdc++.h>
using namespace std;
struct monkey{
int num;
int next;
}a[1010]; int main(){
int n,k,count=0,remain,cur,pre;
cin>>n>>k;
for(int i=1;i<n;i++){
a[i].num=i;
a[i].next=i+1;
} a[n].num=n;
a[n].next=1;
remain=n;
cur=1;
pre=n;
while(remain>1){
count++;
if(count==k){
a[pre].next=a[cur].next;
remain--;
count=0;
}else{
pre = cur;
}
cur=a[cur].next;
}
cout<<a[cur].num<<endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
struct monkey{
int num;//当前猴子位置
int next;//下一个猴子位置
}a[1010]; int main(){
//n只猴子 报数到k时出圈
int n,k;
//从0报数开始计数到count=k时出圈 remain当前还剩余可报数的猴子
int count=0,remain;
// 当前猴子位置和前一个猴子位置 当前出队,需要修改pre的next
int cur,pre; cin>>n>>k;
for(int i=1;i<n;i++){//n-1个点建立循环链表
a[i].num=i;
a[i].next=i+1;
}
//第n个点特殊处理
a[n].num=n;//第n个点建立循环链表
a[n].next=1;//第n个点建立循环链表 remain=n;//默认剩余可以报数为n int kk=k%remain;
if(kk==0){
kk=remain;
}
cur=1;//当前从第一个开始
pre=n;//删除第一个使用
while(remain>1){//报数到k出圈 剩下最后一个猴子为止
count++;//报数加1
if(count==kk){//报数到k的猴子出圈
a[pre].next=a[cur].next;//链表中删除当前猴子
remain--;//出圈 猴子数减一
count=0;//从0开始重新报数
kk=k%remain;
if(kk==0){
kk=remain;
}
}else{
pre = cur;//记录当前猴子的前一个猴子位置
}
cur=a[cur].next;//当前猴子的下一个位置
}
cout<<a[cur].num<<endl;//剩余最后一个猴子的位置
return 0;
}

奖学金

http://oj.61coding.cn/problem.php?cid=1028&pid=3

#include<bits/stdc++.h>
using namespace std;
struct node{
int num,chi,mat,eng,tot;
};
node a[311];
bool cmp(node x,node y){
if (x.tot !=y.tot){
return x.tot>y.tot;
}else if (x.chi!=y.chi){
return x.chi>y.chi;
} else return x.num<y.num;
}
int main(){
int n; cin>>n;
for (int i=1;i<=n;i++){
cin>>a[i].chi>>a[i].mat>>a[i].eng;
a[i].num=i;
a[i].tot=a[i].chi+a[i].eng+a[i].mat;
}
sort(a+1,a+n+1,cmp);
for (int i=1;i<=5;i++){
cout<<a[i].num<<" "<<a[i].tot<<endl;
}
return 0;
}

桌面窗体重叠

http://oj.61coding.cn/problem.php?cid=1028&pid=4

#include<bits/stdc++.h>
using namespace std;
struct twindow{
int left,right,top,bottom;
};
twindow wina,winb,tmp; twindow indata(){
twindow tmp;
cin >> tmp.left >> tmp.right >> tmp.top >> tmp.bottom;
return tmp;
} int main(){ wina = indata();
winb = indata();
tmp.left = max(wina.left,winb.left);
tmp.right = min(wina.right,winb.right);
tmp.top = max(wina.top,winb.top);
tmp.bottom = min(wina.bottom,winb.bottom);
int s = (tmp.right - tmp.left) * (tmp.bottom - tmp.top);
if((tmp.right <= tmp.left) || (tmp.bottom <= tmp.top)) s = 0;
cout << s << endl;
return 0;
}

C++数据结构-结构体的更多相关文章

  1. C语言-数据结构-结构体

    一.结构体的定义 数组(Array)是一组具有相同类型的数据的集合.但在实际的编程过程中,我们往往还需要一组类型不同的数据,例如对于学生信息登记表,姓名为字符串,学号为整数,年龄为整数,所在的学习小组 ...

  2. Swift超详细的基础语法-结构体,结构体构造器,定义成员方法, 值类型, 扩充函数

    知识点 基本概念 结构体的基本使用 结构体构造器(构造函数/构造方法) 结构体扩充函数(方法), 又称成员方法 结构体是值类型 1. 基本概念 1.1 概念介绍 结构体(struct)是由一系列具有相 ...

  3. 数据结构基础——结构体struct及类型别名typedef的使用

    一.结构体的创建 在C语言中,实现数据结构的一种常用方法便是使用结构体(structure)其示例代码如下: struct stu { int num; char ch; }; struct表示创建结 ...

  4. Go 结构体和map等数据结构转json字符串

    Go语言中使用json包中的 Marshal() 函数将数据结构转成json字符串,源代码: func Marshal(v interface{}) ([]byte, error) { e := ne ...

  5. 数据结构复习之C语言指针与结构体

    数据结构指针复习: #include <stdio.h> void main() { ] = {, , , , }; // a[3] == *(3+a) printf(+a)); // a ...

  6. 解惑结构体与结构体指针(struct与typedef struct在数据结构的第一道坎)

    /* 数据结构解惑01  在数据结构中会看到 typedef struct QNode { QElemType data; //数据域 struct QNode *next; //指针域 }QNode ...

  7. Go语言【第十一篇】:Go数据结构之:结构体

    Go语言结构体 Go语言中数组可以存储同一类型的数据,但在结构体中我们可以为不同项定义不同的数据类型,结构体是由一系列具有相同类型或不同类型数据构成的集合.结构体表示一项记录,比如:保存图书馆的书籍记 ...

  8. go语言结构体

    定义: 是一种聚合的数据类型,是由零个或多个任意类型的值聚合成的实体. 成员: 每个值称为结构体的成员. 示例: 用结构体的经典案例处理公司的员工信息,每个员工信息包含一个唯一的员工编号.员工的名字. ...

  9. C语言中的结构体

    用户自己建立自己的结构体类型 1.  定义和使用结构体变量 (1).结构体的定义 C语言允许用户自己建立由不同类型数据组成的组合型的数据结构,它称为结构体. (2).声明一个结构体类型的一般形式为: ...

  10. C语言、结构体 定义

    C语言允许用户自己建立由 不同类型数据组成的组合型数据结构 成为结构体. struct Student { int num; //学号 ]; //姓名为字符串 char sex; //性别为字符型 i ...

随机推荐

  1. 前端h5适配刘海屏和滴水屏

    前端适配苹果刘海屏,安卓刘海屏水滴瓶 其实w3c早就为我们提供了解决方法(CSS3新特性viewport-fit) 在w3c.org官方给出的关于圆形展示(Round display)的标准中, 提到 ...

  2. Python实验报告(第7章)

    实验7:面向对象程序设计 一.实验目的和要求 1.了解面向对象的基本概念(对象.类.构造方法): 2.学会类的定义和使用: 3.掌握属性的创建和修改: 4.掌握继承的基本语法. 二.实验环境 软件版本 ...

  3. 痞子衡嵌入式:Farewell, 我的写博故事2016-2019

    -- 题图:苏州天平山枫叶 现在是 2022 年末,痞子衡又要起笔博文年终总结了,看着 2020 年之前的博文总结缺失,始终觉得缺憾,所以写下此篇 2016 - 2019 总结合辑.2016 年之前, ...

  4. python之路36 MySQL查询关键字

    报错及作业讲解 报错 1.粗心大意 单词拼写错误 2.手忙脚乱 不会看报错 思考错误的核心 作业讲解 '''表与表中数据的关系可能会根据业务逻辑的不同 发生改变 不是永远固定的''' 服务器表与应用程 ...

  5. python31 网络并发编程方法

    同步与异步 用来表达任务的提交方式 同步 提交完任务之后原地等待任务的返回结果 期间不做任何事 异步 提交完任务之后不原地等待任务的返回结果 直接去做其他事 有结果自动通知 阻塞与非阻塞 用来表达任务 ...

  6. 经典问题 1 —— DAG 上区间限制拓扑序

    问题描述 给定一个 DAG,求一个拓扑序,使得节点 \(i\) 的拓扑序 \(\in [l_i,r_i]\). 题解 首先进行一个预处理:对于所有 \(u\),令 \(\forall (v,u)\in ...

  7. 十九岁纪念|HBD To ME

    过了20年,终于摆脱了令人讨厌的应试生活.19岁,一半是高三,一半是大学,由高考,分成两半.说实话,我觉得大学也没有那么令人向往,换种方式读高四吧.长大了,对时间也没有什么概念了.要不是19岁在我的家 ...

  8. Node.js学习笔记----day05(MongonDB详情)

    认真学习,认真记录,每天都要有进步呀!!! 加油叭!!! 一.es6中的find() 方法的原理 EcmaScript 6 对数组新增了很多方法 比如,find find 接收一个方法作为参数,方法内 ...

  9. Mybatis Plus整合PageHelper分页的实现示例

    1.依赖引入 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pag ...

  10. HOMER docker版本安装详细流程

    概述 HOMER是一款100%开源的针对SIP/VOIP/RTC的抓包工具和监控工具. HOMER是一款强大的.运营商级.可扩展的数据包和事件捕获系统,是基于HEP/EEP协议的VoIP/RTC监控应 ...