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

做网站 信科网络培训班有哪些课程

做网站 信科网络,培训班有哪些课程,好的手机端网站模板下载安装,湖南视频网站建设文章目录 题目输入格式输出格式输入样例输出样例 题解解题思路完整代码 编程练习题目集目录 题目 Given a constant K K K and a singly linked list L L L, you are supposed to reverse the links of every K K K elements on L L L. For example, given L being 1 → …

文章目录

  • 题目
    • 输入格式
    • 输出格式
    • 输入样例
    • 输出样例
  • 题解
    • 解题思路
    • 完整代码

编程练习题目集目录

题目

  Given a constant K K K and a singly linked list L L L, you are supposed to reverse the links of every K K K elements on L L L. For example, given L being 1 → 2 → 3 → 4 → 5 → 6 1→2→3→4→5→6 123456, if K = 3 K=3 K=3, then you must output 3 → 2 → 1 → 6 → 5 → 4 3→2→1→6→5→4 321654; if K = 4 K=4 K=4, you must output 4 → 3 → 2 → 1 → 5 → 6 4→3→2→1→5→6 432156.

输入格式

  Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N ( ≤ 1 0 5 ) N(≤10^5) N105 which is the total number of nodes, and a positive K ( ≤ N ) K(≤N) KN which is the length of the sublist to be reversed. The address of a node is a 5-digit nonnegative integer, and NULL is represented by − 1 -1 1.

  Then N N N lines follow, each describes a node in the format:

Address Data Next

  where Address is the position of the node, Data is an integer, and Next is the position of the next node.

输出格式

  For each case, output the resulting ordered linked list. Each node occupies a line, and is printed in the same format as in the input.

输入样例

00100 6 4
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 33218

输出样例

00000 4 33218
33218 3 12309
12309 2 00100
00100 1 99999
99999 5 68237
68237 6 -1

题解

解题思路

  使用两个数组 d a t a data data n e x t next next 分别存储每个节点的数据和指向下一个节点的指针。从头节点开始,按顺序将节点的地址存储在数组 l i s t list list 中,构建链表的顺序结构。将 l i s t list list 中的节点按分组大小 K K K 进行反转。将反转后的节点顺序存储在结果数组 r e s u l t result result 中,即可。

完整代码

#include <iostream>
using namespace std;int main(void) {int number, k, n, sum = 0;cin >> number >> n >> k;int temp, data[100005], next[1000005], list[100005], result[100005];// 读取链表节点信息for (int i = 0; i < n; i++) {cin >> temp;cin >> data[temp] >> next[temp];}// 构建初始链表顺序while (number != -1) {list[sum++] = number;number = next[number];}// 复制初始链表到结果数组for (int i = 0; i < sum; i++) result[i] = list[i];// 按照分组大小 K 反转链表中的每个分组for (int i = 0; i < (sum - sum % k); i++)result[i] = list[i / k * k + k - 1 - i % k];// 输出反转后的链表for (int i = 0; i < sum - 1; i++)printf("%05d %d %05d\n", result[i], data[result[i]], result[i + 1]);printf("%05d %d -1", result[sum - 1], data[result[sum - 1]]);return 0;
}
http://www.dtcms.com/wzjs/22886.html

相关文章:

  • 网站公司源码国际新闻最新消息战争
  • 名医工作室 网站建设关键词规划师
  • 帮别人做网站需要什么能力广告传媒公司经营范围
  • 安阳网站优化公司推荐品牌推广
  • 卡盟网站模板手机怎么做网站
  • wordpress如何换图片seo优化方案策划书
  • 360做网站的百度seo收录软件
  • 做支付行业招代理一般上什么网站seo专员岗位要求
  • 专业做数据的网站有哪些长春seo推广
  • 开网站建设公司友情链接怎么交换
  • 网站开发的背景知识与相关技术线上营销
  • 武安网站制作人工智能培训班收费标准
  • 企业网站管理系统模版源码北京网站制作公司
  • 深圳网站建设公司哪家专业seo点击工具
  • 南宁网站建设报价晋城seo
  • 电子商务网站开发规划长春百度seo排名
  • app开发网站建设小程序开发软件
  • python做网站的开发宁波seo自然优化技术
  • wordpress七牛设置厦门网站seo
  • 网站开发程序员岗位职责百度 营销推广怎么收费
  • 检索类的网站建设国家免费技能培训官网
  • 做网站公司怎么赚钱小程序商城
  • vpsputty做网站2021最近比较火的营销事件
  • 做公司网站要去哪里找人做网络优化工具app手机版
  • 重庆网站建设 渝郑州发布最新通告
  • 做网站可以不买域名和主机吗引流推广多少钱一个
  • 怎么建一个公司运营网站网站建设方案内容
  • 网站的建设和维护成本顾问
  • 不同接入商备案网站广告软文范例200字
  • wordpress 登入单页关键词优化费用