当前位置: 首页 > news >正文

【C/PTA —— 15.结构体2(课外实践)】

C/PTA —— 15.结构体2(课外实践)

  • 7-1 一帮一
  • 7-2 考试座位号
  • 7-3 新键表输出
  • 7-4 可怕的素质
  • 7-5 找出同龄者
  • 7-6 排队
  • 7-7 军训

7-1 一帮一

在这里插入图片描述

#include<stdio.h>
#include<string.h>struct student
{int a;char name[20];
};struct student1
{int b;char name1[20];
};int main()
{struct student  s1[50];struct student1 s2[50];struct student1 s3[50];int i, n, j = 0, t = 0, c, d;scanf("%d", &n);for (i = 0; i < n; i++){scanf("%d %s", &s1[i].a, s1[i].name);}for (i = 0; i < n; i++){if (s1[i].a == 1){s2[j].b = i;strcpy(s2[j].name1, s1[i].name);j++;}if (s1[i].a == 0){s3[t].b = i;strcpy(s3[t].name1, s1[i].name);t++;}}c = n / 2 - 1, d = n / 2 - 1;j = 0, t = 0;for (i = 0; i < n / 2; i++){if (s3[j].b < s2[t].b){printf("%s %s\n", s3[j].name1, s2[c].name1);j++;c--;}else{printf("%s %s\n", s2[t].name1, s3[d].name1);t++;d--;}}return 0;
}

7-2 考试座位号

在这里插入图片描述

#include<stdio.h>
struct student
{char num[17];int s;int k;
};int main()
{int n = 0;scanf("%d", &n);struct student stu[1000]={0};for (int i = 0; i < n; i++){scanf("%s %d %d", stu[i].num, &stu[i].s, &stu[i].k);}int m = 0,ret;     scanf("%d", &m);for (int i = 0; i < m; i++){scanf("%d", &ret);int j=0;for (j = 0; j < n; j++){if (ret == stu[j].s){printf("%s %d\n", stu[j].num, stu[j].k);}}}return 0;
}

7-3 新键表输出

在这里插入图片描述

#include <stdio.h>
#include <stdlib.h>// 定义链表节点结构体
typedef struct ListNode {int val;struct ListNode* next;
} ListNode;// 定义头节点指针
ListNode* createList() {ListNode* head = NULL;int num;while (1) {scanf("%d", &num);if (num == -1) {break;}ListNode* newNode = (ListNode*)malloc(sizeof(ListNode));newNode->val = num;newNode->next = NULL;if (head == NULL) {head = newNode;} else {ListNode* cur = head;while (cur->next != NULL) {cur = cur->next;}cur->next = newNode;}}return head;
}// 遍历链表,将奇数值节点插入新链表
ListNode* createNewList(ListNode* head) {ListNode* newHead = NULL;ListNode* cur = head;while (cur != NULL) {if (cur->val % 2 != 0) {ListNode* newNode = (ListNode*)malloc(sizeof(ListNode));newNode->val = cur->val;newNode->next = NULL;if (newHead == NULL) {newHead = newNode;} else {ListNode* temp = newHead;while (temp->next != NULL) {temp = temp->next;}temp->next = newNode;}}cur = cur->next;}return newHead;
}// 打印链表
void printList(ListNode* head) {ListNode* cur = head;printf("%d", cur->val);cur = cur->next;while (cur != NULL) {printf(" %d", cur->val);cur = cur->next;}printf("\n");
}int main() {// 创建链表ListNode* head = createList();// 创建新链表ListNode* newHead = createNewList(head);// 打印新链表printList(newHead);return 0;
}

7-4 可怕的素质

在这里插入图片描述

#include <stdio.h>
#include<stdlib.h>
typedef struct student student;
struct student{int ret;struct student *next;
};
student *insert(int n);
void prin(student*,int n);
int main(){int n;student *stu1;scanf("%d", &n);stu1=insert(n);prin(stu1, n);return 0;
}
void prin(student*stu1,int n){student *p = stu1->next;while(p!=NULL){if(p->next!=NULL)printf("%d ", p->ret);elseprintf("%d", p->ret);p = p->next;}
}
student *insert(int n){student *head;head = (struct student*) malloc(sizeof(student));head->next = NULL;student *p = head, *q;int pos = 0;for (int i = 1; i <= n;i++){scanf("%d", &pos);q = (struct student *)malloc(sizeof(student));q->ret = i;q->next = NULL;if(i==1){head->next = q;}else if(pos==0){q->next = head->next;head->next = q;}else if(pos!=0){p = head->next;while(p->ret!=pos){p = p->next;}q->next = p->next;p->next = q;}}return head;
}

7-5 找出同龄者

在这里插入图片描述

#include<stdio.h>
typedef struct student
{char name[10];int age;
}student;
int main()
{int n = 0;student stu[100];scanf("%d", &n);for (int i = 0; i < n; i++){scanf("%s %d", stu[i].name, &stu[i].age);}int m = 0;scanf("%d", &m);int j = 0;for (int i = 0; i < n; i++){if (stu[i].age != m){printf("%s", stu[i].name);j = i;break;}}for (int i = j + 1; i < n; i++){if (stu[i].age != m){printf(" %s", stu[i].name);}}return 0;
}

7-6 排队

在这里插入图片描述

#include<stdio.h>
#include<stdlib.h>
typedef struct student student;
//还是双链表好用
struct student{student *prior;student *next;int ri, bi, fi,ret;double height;student *arret;
};
student* create(int n){student *head, *p, *q;head = (student*)malloc(sizeof(student));head->prior = NULL;head->next = NULL;head->arret = NULL;for (int i = 1; i <= n;i++){q = (student*)malloc(sizeof(student));scanf("%lf", &q->height);q->ret = i;if(i==1){head->next = q;head->arret = q;q->arret = NULL;q->prior = head;q->next = NULL;}else {p->next = q;p->arret = q;q->arret = NULL;q->prior = p;q->next = NULL;}p = q;}return head;
}
void swap(student *p1,student *p2){student *p1f, *p1b, *p2f, *p2b;p1f = p1->prior;p1b = p1->next;p2f = p2->prior;p2b = p2->next;p1f->next = p1b;p1b->prior = p1f;p1b->next = p2f;p2f->prior = p1b;p2f->next = p2b;if(p2b!=NULL)p2b->prior = p2f;
}
int main(){int n;scanf("%d", &n);student *stu1;stu1=create(n);student *p = stu1->next;for (int i = 1; i < n;i++){p = stu1->next;for (int j = 1; j < n - i + 1;j++){if(p->height<p->next->height){swap(p,p->next);}else p = p->next;}}p = stu1->next;for (int i = 1; i <= n;i++){if(i==1){p->fi = 0;p->bi = p->next->ret;}else if(i==n){p->bi = 0;p->fi = p->prior->ret;}else {p->fi = p->prior->ret;p->bi = p->next->ret;}p->ri = i;p = p->next;}p = stu1->arret;for (int i = 1; i <= n;i++){printf("%d %d %d\n", p->ri, p->fi, p->bi);p = p->arret;}return 0;
}

7-7 军训

在这里插入图片描述

#include<stdio.h>
#include<stdlib.h>
typedef struct queue queue;
struct queue{int rank;queue *prior;queue *next;int size;
};
void print(queue *queue1){queue *p = queue1->next;while(p!=NULL){if(p->next!=NULL)printf("%d ", p->rank);elseprintf("%d\n", p->rank);p = p->next;}
}
queue *delete_LB(queue *queue1){queue *k = queue1;queue1->prior->next = queue1->next;if(queue1->next!=NULL)queue1->next->prior = queue1->prior;queue1 = queue1->prior;free(k);return queue1;
}
queue *create(int n){queue *head;queue *p, *q;head = (queue*)malloc(sizeof(queue));head->prior = NULL;head->next = NULL;for (int i = 1; i <= n;i++){q = (queue *)malloc(sizeof(queue));q->rank = i;if(i==1){head->next = q;q->prior = head;q->next = NULL;}else {p->next = q;q->prior = p;q->next = NULL;}p = q;}return head;
}
int main(){int n;scanf("%d", &n);queue document[105];queue *a;for (int i = 1; i <= n;i++){int count;scanf("%d", &count);a = create(count);a->size = count;queue *p;while(a->size>3){p = a->next;for (int j = 1; j <= count; j++){if (j % 2 == 0)//这里无需判断是否size>3,因为无论是否满足,都必须在进行的一轮内将所有2的报数删除;{p=delete_LB(p);a->size--;}p = p->next;}count = a->size;p = a->next;if(a->size>3)//这里加上size>3的判断才能保证n=40的情况下37不会被删除,否则还会进行一次j=3时的删除操作;特殊情况(即处理完上一轮2的报数后size恰好为3,但是此时没有加入判断的话循环会继续运行,会多删除1项){for (int j = 1; j <= count; j++){if (j % 3 == 0) {p = delete_LB(p);a->size--;}p = p->next;}}count = a->size;}document[i] = *a;}for (int i = 1; i <= n;i++){print(&document[i]);}return 0;
}

相关文章:

【C/PTA —— 15.结构体2(课外实践)】

C/PTA —— 15.结构体2&#xff08;课外实践&#xff09; 7-1 一帮一7-2 考试座位号7-3 新键表输出7-4 可怕的素质7-5 找出同龄者7-6 排队7-7 军训 7-1 一帮一 #include<stdio.h> #include<string.h>struct student {int a;char name[20]; };struct student1 {int …...

艾泊宇产品战略:适应新消费时代,产品战略指南以应对市场挑战和提升盈利

赚钱越来越难&#xff0c;这是许多企业和个人都感到困惑的问题。 然而&#xff0c;艾泊宇产品战略告诉大家&#xff0c;我们不能把这个问题简单地归咎于经济环境或市场竞争&#xff0c;而是需要从更深层次去思考和解决。 本文将从多个角度去剖析这个问题&#xff0c;并探讨在…...

使用autodl服务器,两个3090显卡上运行, Yi-34B-Chat-int4模型,并使用vllm优化加速,显存占用42G,速度23 words/s

1&#xff0c;演示视频地址 https://www.bilibili.com/video/BV1Hu4y1L7BH/ 使用autodl服务器&#xff0c;两个3090显卡上运行&#xff0c; Yi-34B-Chat-int4模型&#xff0c;用vllm优化&#xff0c;增加 --num-gpu 2&#xff0c;速度23 words/s 2&#xff0c;使用3090显卡 和…...

ORACLE数据库实验总集 实验六 SQL 语句应用

一、 实验目的 &#xff08;1&#xff09; 掌握数据的插入&#xff08;INSERT&#xff09;、 修改&#xff08;UPDATE&#xff09; 和删除&#xff08;DELETE&#xff09; 操作。 &#xff08;2&#xff09; 掌握不同类型的数据查询&#xff08;SELECT&#xff09; 操作。 二、…...

[FPGA 学习记录] 快速开发的法宝——IP核

快速开发的法宝——IP核 文章目录 1 IP 核是什么2 为什么要使用 IP 核3 IP 核的存在形式4 IP 核的缺点5 Quartus II 软件下 IP 核的调用6 Altera IP 核的分类 在本小节当中&#xff0c;我们来学习一下 IP 核的相关知识。 IP 核在 FPGA 开发当中应用十分广泛&#xff0c;它被称为…...

每日一题:LeetCode-11.盛水最多的容器

每日一题系列&#xff08;day 13&#xff09; 前言&#xff1a; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f50e…...

查看电脑cuda版本

1.找到NVODIA控制面板 输入NVIDIA搜索即可 出现NVIDIA控制面板 点击系统信息 2.WINR 输入nvidia-smi 检查了一下&#xff0c;电脑没用过GPU&#xff0c;连驱动都没有 所以&#xff0c;装驱动…… 选版本&#xff0c;下载 下载后双击打开安装 重新输入nvidia-smi 显示如下…...

centos7 docker Mysql8 搭建主从

Mysql8 搭建主从 docker的安装docker-compose的安装安装mysql配置主从在master配置在slave中配置在master中创建同步用户在slave中连接 测试连接测试配置测试数据同步遇到的问题id重复错误执行事务出错&#xff0c;跳过错误my.cnf 不删除多余配置的错误可能用到的命令 docker的…...

CSS中 设置文字下划线 的几种方法

在网页设计和开发中&#xff0c;我们经常需要对文字进行样式设置&#xff0c;包括字体,颜色&#xff0c;大小等&#xff0c;其中&#xff0c;设置文字下划线是一种常见需求 一 、CSS种使用 text-decoration 属性来设置文字的装饰效果&#xff0c;包括下划线。 常用的取值&…...

Docker构建自定义镜像

创建一个docker-demo的文件夹,放入需要构建的文件 主要是配置Dockerfile文件 第一种配置方法 # 指定基础镜像 FROM ubuntu:16.04 # 配置环境变量&#xff0c;JDK的安装目录 ENV JAVA_DIR/usr/local# 拷贝jdk和java项目的包 COPY ./jdk8.tar.gz $JAVA_DIR/ COPY ./docker-demo…...

C#生成Token字符串

Token字符串来保证数据安全性&#xff0c;如身份验证、跨域访问等。但是由于Token字符串的长度比较长&#xff0c;可能会占用过多的空间和带宽资源&#xff0c;因此我们需要生成短的Token字符串 方法一&#xff1a;使用Base64编码 Base64编码是一种常用的编码方式&#xff0c…...

文献速递:多模态影像组学文献分享:生成一种多模态人工智能模型以区分甲状腺良性和恶性滤泡性肿瘤:概念验证研究

文献速递&#xff1a;多模态影像组学文献分享&#xff1a;生成一种多模态人工智能模型以区分甲状腺良性和恶性滤泡性肿瘤&#xff1a;概念验证研究 文献速递介绍 近年来&#xff0c;人工智能&#xff08;AI&#xff09;领域日益被探索&#xff0c;作为一种增强传统医学诊断和…...

Docker创建RocketMQ和RocketMQ控制台

安装RocketMQ 安装最新版本的RocketMQ&#xff08;名为RocketMQ&#xff09;在Docker上的过程大致可以分为以下步骤&#xff1a; 1. 准备工作 确保你的系统中已经安装了Docker。可以通过运行 docker --version 来验证Docker是否已安装及其版本信息。 2. 拉取RocketMQ镜像 …...

Python---面向对象其他特性

1、类属性 Python中&#xff0c;属性可以分为实例属性和类属性。 类属性就是 类对象中定义的属性&#xff0c;它被该类的所有实例对象所共有。通常用来记录 与这类相关 的特征&#xff0c;类属性 不会用于记录 具体对象的特征。 在Python中&#xff0c;一切皆对象。类也是一…...

【Ambari】Python调用Rest API 获取YARN HA状态信息并发送钉钉告警

&#x1f984; 个人主页——&#x1f390;开着拖拉机回家_Linux,大数据运维-CSDN博客 &#x1f390;✨&#x1f341; &#x1fa81;&#x1f341;&#x1fa81;&#x1f341;&#x1fa81;&#x1f341;&#x1fa81;&#x1f341; &#x1fa81;&#x1f341;&#x1fa81;&am…...

linux之buildroot(3)配置软件包

Linux之buildroot(3)配置软件包 Author&#xff1a;Onceday Date&#xff1a;2023年11月30日 漫漫长路&#xff0c;才刚刚开始… 全系列文章请查看专栏: buildroot编译框架_Once_day的博客-CSDN博客。 参考文档&#xff1a; Buildroot - Making Embedded Linux Easymdev.t…...

学会用bash在linux写脚本 (一)

本章主要介绍如何使用bash写脚本。 了解通配符 了解变量 了解返回值和数值运算 grep的用法是“grep 关键字 file”&#xff0c;意思是从file中过滤出含有关键字的行。 例如&#xff0c;grep root /var/log/messages&#xff0c;意思是从/var/log/messages 中过滤出含有root …...

Leetcode 2949. Count Beautiful Substrings II

Leetcode 2949. Count Beautiful Substrings II 1. 解题思路2. 代码实现 Leetcode 2949. Count Beautiful Substrings II 1. 解题思路 这一题真的很丢脸&#xff0c;居然没有搞定&#xff0c;是看了大佬们的思路之后才想明白的&#xff0c;就感觉丢脸丢大了…… 这道题讲道…...

【Python系列】Python函数

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…...

自定义TypeHandler 将mysql返回的逗号分隔的String转换到List

sql执行如下&#xff1a; 这里我定义的接受类&#xff1a; 但是这里报了错JSON parse error: Cannot deserialize value of type java.util.ArrayList<java.lang.String>from Object value (token JsonToken.START_OBJECT); nested exception is com.fasterxml.jackson…...

React第五十七节 Router中RouterProvider使用详解及注意事项

前言 在 React Router v6.4 中&#xff0c;RouterProvider 是一个核心组件&#xff0c;用于提供基于数据路由&#xff08;data routers&#xff09;的新型路由方案。 它替代了传统的 <BrowserRouter>&#xff0c;支持更强大的数据加载和操作功能&#xff08;如 loader 和…...

DockerHub与私有镜像仓库在容器化中的应用与管理

哈喽&#xff0c;大家好&#xff0c;我是左手python&#xff01; Docker Hub的应用与管理 Docker Hub的基本概念与使用方法 Docker Hub是Docker官方提供的一个公共镜像仓库&#xff0c;用户可以在其中找到各种操作系统、软件和应用的镜像。开发者可以通过Docker Hub轻松获取所…...

centos 7 部署awstats 网站访问检测

一、基础环境准备&#xff08;两种安装方式都要做&#xff09; bash # 安装必要依赖 yum install -y httpd perl mod_perl perl-Time-HiRes perl-DateTime systemctl enable httpd # 设置 Apache 开机自启 systemctl start httpd # 启动 Apache二、安装 AWStats&#xff0…...

大数据零基础学习day1之环境准备和大数据初步理解

学习大数据会使用到多台Linux服务器。 一、环境准备 1、VMware 基于VMware构建Linux虚拟机 是大数据从业者或者IT从业者的必备技能之一也是成本低廉的方案 所以VMware虚拟机方案是必须要学习的。 &#xff08;1&#xff09;设置网关 打开VMware虚拟机&#xff0c;点击编辑…...

在 Nginx Stream 层“改写”MQTT ngx_stream_mqtt_filter_module

1、为什么要修改 CONNECT 报文&#xff1f; 多租户隔离&#xff1a;自动为接入设备追加租户前缀&#xff0c;后端按 ClientID 拆分队列。零代码鉴权&#xff1a;将入站用户名替换为 OAuth Access-Token&#xff0c;后端 Broker 统一校验。灰度发布&#xff1a;根据 IP/地理位写…...

聊一聊接口测试的意义有哪些?

目录 一、隔离性 & 早期测试 二、保障系统集成质量 三、验证业务逻辑的核心层 四、提升测试效率与覆盖度 五、系统稳定性的守护者 六、驱动团队协作与契约管理 七、性能与扩展性的前置评估 八、持续交付的核心支撑 接口测试的意义可以从四个维度展开&#xff0c;首…...

全面解析各类VPN技术:GRE、IPsec、L2TP、SSL与MPLS VPN对比

目录 引言 VPN技术概述 GRE VPN 3.1 GRE封装结构 3.2 GRE的应用场景 GRE over IPsec 4.1 GRE over IPsec封装结构 4.2 为什么使用GRE over IPsec&#xff1f; IPsec VPN 5.1 IPsec传输模式&#xff08;Transport Mode&#xff09; 5.2 IPsec隧道模式&#xff08;Tunne…...

Rapidio门铃消息FIFO溢出机制

关于RapidIO门铃消息FIFO的溢出机制及其与中断抖动的关系&#xff0c;以下是深入解析&#xff1a; 门铃FIFO溢出的本质 在RapidIO系统中&#xff0c;门铃消息FIFO是硬件控制器内部的缓冲区&#xff0c;用于临时存储接收到的门铃消息&#xff08;Doorbell Message&#xff09;。…...

重启Eureka集群中的节点,对已经注册的服务有什么影响

先看答案&#xff0c;如果正确地操作&#xff0c;重启Eureka集群中的节点&#xff0c;对已经注册的服务影响非常小&#xff0c;甚至可以做到无感知。 但如果操作不当&#xff0c;可能会引发短暂的服务发现问题。 下面我们从Eureka的核心工作原理来详细分析这个问题。 Eureka的…...

使用Matplotlib创建炫酷的3D散点图:数据可视化的新维度

文章目录 基础实现代码代码解析进阶技巧1. 自定义点的大小和颜色2. 添加图例和样式美化3. 真实数据应用示例实用技巧与注意事项完整示例(带样式)应用场景在数据科学和可视化领域,三维图形能为我们提供更丰富的数据洞察。本文将手把手教你如何使用Python的Matplotlib库创建引…...