当前位置: 首页 > 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…...

智慧工地云平台源码,基于微服务架构+Java+Spring Cloud +UniApp +MySql

智慧工地管理云平台系统&#xff0c;智慧工地全套源码&#xff0c;java版智慧工地源码&#xff0c;支持PC端、大屏端、移动端。 智慧工地聚焦建筑行业的市场需求&#xff0c;提供“平台网络终端”的整体解决方案&#xff0c;提供劳务管理、视频管理、智能监测、绿色施工、安全管…...

23-Oracle 23 ai 区块链表(Blockchain Table)

小伙伴有没有在金融强合规的领域中遇见&#xff0c;必须要保持数据不可变&#xff0c;管理员都无法修改和留痕的要求。比如医疗的电子病历中&#xff0c;影像检查检验结果不可篡改行的&#xff0c;药品追溯过程中数据只可插入无法删除的特性需求&#xff1b;登录日志、修改日志…...

FastAPI 教程:从入门到实践

FastAPI 是一个现代、快速&#xff08;高性能&#xff09;的 Web 框架&#xff0c;用于构建 API&#xff0c;支持 Python 3.6。它基于标准 Python 类型提示&#xff0c;易于学习且功能强大。以下是一个完整的 FastAPI 入门教程&#xff0c;涵盖从环境搭建到创建并运行一个简单的…...

《用户共鸣指数(E)驱动品牌大模型种草:如何抢占大模型搜索结果情感高地》

在注意力分散、内容高度同质化的时代&#xff0c;情感连接已成为品牌破圈的关键通道。我们在服务大量品牌客户的过程中发现&#xff0c;消费者对内容的“有感”程度&#xff0c;正日益成为影响品牌传播效率与转化率的核心变量。在生成式AI驱动的内容生成与推荐环境中&#xff0…...

什么是库存周转?如何用进销存系统提高库存周转率?

你可能听说过这样一句话&#xff1a; “利润不是赚出来的&#xff0c;是管出来的。” 尤其是在制造业、批发零售、电商这类“货堆成山”的行业&#xff0c;很多企业看着销售不错&#xff0c;账上却没钱、利润也不见了&#xff0c;一翻库存才发现&#xff1a; 一堆卖不动的旧货…...

SpringBoot+uniapp 的 Champion 俱乐部微信小程序设计与实现,论文初版实现

摘要 本论文旨在设计并实现基于 SpringBoot 和 uniapp 的 Champion 俱乐部微信小程序&#xff0c;以满足俱乐部线上活动推广、会员管理、社交互动等需求。通过 SpringBoot 搭建后端服务&#xff0c;提供稳定高效的数据处理与业务逻辑支持&#xff1b;利用 uniapp 实现跨平台前…...

第一篇:Agent2Agent (A2A) 协议——协作式人工智能的黎明

AI 领域的快速发展正在催生一个新时代&#xff0c;智能代理&#xff08;agents&#xff09;不再是孤立的个体&#xff0c;而是能够像一个数字团队一样协作。然而&#xff0c;当前 AI 生态系统的碎片化阻碍了这一愿景的实现&#xff0c;导致了“AI 巴别塔问题”——不同代理之间…...

Spring Cloud Gateway 中自定义验证码接口返回 404 的排查与解决

Spring Cloud Gateway 中自定义验证码接口返回 404 的排查与解决 问题背景 在一个基于 Spring Cloud Gateway WebFlux 构建的微服务项目中&#xff0c;新增了一个本地验证码接口 /code&#xff0c;使用函数式路由&#xff08;RouterFunction&#xff09;和 Hutool 的 Circle…...

回溯算法学习

一、电话号码的字母组合 import java.util.ArrayList; import java.util.List;import javax.management.loading.PrivateClassLoader;public class letterCombinations {private static final String[] KEYPAD {"", //0"", //1"abc", //2"…...

接口自动化测试:HttpRunner基础

相关文档 HttpRunner V3.x中文文档 HttpRunner 用户指南 使用HttpRunner 3.x实现接口自动化测试 HttpRunner介绍 HttpRunner 是一个开源的 API 测试工具&#xff0c;支持 HTTP(S)/HTTP2/WebSocket/RPC 等网络协议&#xff0c;涵盖接口测试、性能测试、数字体验监测等测试类型…...