C++数据结构-结构体
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++数据结构-结构体的更多相关文章
- C语言-数据结构-结构体
一.结构体的定义 数组(Array)是一组具有相同类型的数据的集合.但在实际的编程过程中,我们往往还需要一组类型不同的数据,例如对于学生信息登记表,姓名为字符串,学号为整数,年龄为整数,所在的学习小组 ...
- Swift超详细的基础语法-结构体,结构体构造器,定义成员方法, 值类型, 扩充函数
知识点 基本概念 结构体的基本使用 结构体构造器(构造函数/构造方法) 结构体扩充函数(方法), 又称成员方法 结构体是值类型 1. 基本概念 1.1 概念介绍 结构体(struct)是由一系列具有相 ...
- 数据结构基础——结构体struct及类型别名typedef的使用
一.结构体的创建 在C语言中,实现数据结构的一种常用方法便是使用结构体(structure)其示例代码如下: struct stu { int num; char ch; }; struct表示创建结 ...
- Go 结构体和map等数据结构转json字符串
Go语言中使用json包中的 Marshal() 函数将数据结构转成json字符串,源代码: func Marshal(v interface{}) ([]byte, error) { e := ne ...
- 数据结构复习之C语言指针与结构体
数据结构指针复习: #include <stdio.h> void main() { ] = {, , , , }; // a[3] == *(3+a) printf(+a)); // a ...
- 解惑结构体与结构体指针(struct与typedef struct在数据结构的第一道坎)
/* 数据结构解惑01 在数据结构中会看到 typedef struct QNode { QElemType data; //数据域 struct QNode *next; //指针域 }QNode ...
- Go语言【第十一篇】:Go数据结构之:结构体
Go语言结构体 Go语言中数组可以存储同一类型的数据,但在结构体中我们可以为不同项定义不同的数据类型,结构体是由一系列具有相同类型或不同类型数据构成的集合.结构体表示一项记录,比如:保存图书馆的书籍记 ...
- go语言结构体
定义: 是一种聚合的数据类型,是由零个或多个任意类型的值聚合成的实体. 成员: 每个值称为结构体的成员. 示例: 用结构体的经典案例处理公司的员工信息,每个员工信息包含一个唯一的员工编号.员工的名字. ...
- C语言中的结构体
用户自己建立自己的结构体类型 1. 定义和使用结构体变量 (1).结构体的定义 C语言允许用户自己建立由不同类型数据组成的组合型的数据结构,它称为结构体. (2).声明一个结构体类型的一般形式为: ...
- C语言、结构体 定义
C语言允许用户自己建立由 不同类型数据组成的组合型数据结构 成为结构体. struct Student { int num; //学号 ]; //姓名为字符串 char sex; //性别为字符型 i ...
随机推荐
- 基于redis乐观锁实现并发排队 - 基于scrapy运行数量的控制
有个需求场景是这样的,使用redis控制scrapy运行的数量.当系统的后台设置为4时,只允许scapry启动4个任务,多余的任务则进行排队. 概况 最近做了一个django + scrapy + c ...
- @LoadBalanced注解原理
在使用springcloud ribbon客户端负载均衡的时候,可以给RestTemplate bean 加一个@LoadBalanced注解,就能让这个RestTemplate在请求时拥有客户端负载 ...
- 官网下载CentOS系统镜像过程
想学习CentOS系统,但是不知道镜像去哪里搞,随便去个第三方发现要么要注册,要么各种广告病毒,或者好不容易找到官网,不仅全英文,有些专业术语也不懂,本文说明官网下载自己想要的CentOS镜像整个流程 ...
- 使用插件式开发称重仪表驱动,RS232串口对接各类地磅秤数据实现ERP管理
在ERP系统中,采集一线的生产数据是重要工作之一,而称重计量是企业的核心资产数据,人工计重费时费力,还容易出错,重量数据是否正确,直接影响企业的采购或销售额.基于此,由系统对接电子秤实现自动抓取数据是 ...
- YMOI 2019.6.29
题解 YMOI 2019.6.29 放弃FAIOJ,用cena考了一次试.被全方位吊打.. T1 开灯 题面: 在一条无限长的路上,有一排无限长的路灯,编号为1,2,3,4,--. 每一盏灯只有两种可 ...
- 代码小DEMO随笔---JS原生手机版本alert弹框
之前的随笔写的是WEB版本的弹框,这次是手机版本,欢迎路过的大佬们提出更好的写法~~ <!DOCTYPE html> <html lang="en"> &l ...
- JS控制台打印星星,总有你要的那一款~呐~给你小心心哦~~~❤
用JS语句,在控制台中打印星星,你要的是哪一款呢~来认领吧~ 1.左直角星星 效果: 代码: let readline=require("readline-sync"); cons ...
- 迁移学习(DIFEX)《Domain-invariant Feature Exploration for Domain Generalization》
论文信息 论文标题:Domain-invariant Feature Exploration for Domain Generalization论文作者:Wang Lu, Jindong Wang, ...
- Python基本数据类型,用户交互,格式化输出,运算符,多种赋值方式,多种运算符
Python基本数据类型,用户交互,格式化输出,运算符,多种赋值方式,多种运算符 一.Python基本数据类型 1.回顾之前学过的基本数据类型 1.整型(整数) 应用场景:年级,班级人数,年份 代码实 ...
- MATLAB实现随机森林(RF)回归与自变量影响程度分析
本文介绍基于MATLAB,利用随机森林(RF)算法实现回归预测,以及自变量重要性排序的操作. 目录 1 分解代码 1.1 最优叶子节点数与树数确定 1.2 循环准备 1.3 数据划分 1.4 随机 ...