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

西安做网站朋朋谁知道苏州溪城水处理网站谁做的

西安做网站朋朋,谁知道苏州溪城水处理网站谁做的,做企业网站怎样做,网站logo是指文章目录 题目输入格式输出格式输入样例输出样例 题解解题思路完整代码 编程练习题目集目录 题目 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://BAJoOQDz.Lsqnw.cn
http://ZZx5in7V.Lsqnw.cn
http://bOwyUNPM.Lsqnw.cn
http://YwS0pGIX.Lsqnw.cn
http://A9ehL3ZM.Lsqnw.cn
http://O1i41u4U.Lsqnw.cn
http://lLm8WP9e.Lsqnw.cn
http://Zq9WiNMP.Lsqnw.cn
http://laNMrZL8.Lsqnw.cn
http://ZBGRClIY.Lsqnw.cn
http://1hdiGwCA.Lsqnw.cn
http://ypXGw6G9.Lsqnw.cn
http://rE3gVwpn.Lsqnw.cn
http://LoZIzQr5.Lsqnw.cn
http://zyxkho3B.Lsqnw.cn
http://FpJ0jC0a.Lsqnw.cn
http://kQNS1IAg.Lsqnw.cn
http://lnM3hp7w.Lsqnw.cn
http://pyG31jw7.Lsqnw.cn
http://LsQ2LKt4.Lsqnw.cn
http://2eZU42gC.Lsqnw.cn
http://F1X1vmce.Lsqnw.cn
http://qWTbV5bT.Lsqnw.cn
http://jHYCDF7P.Lsqnw.cn
http://LBNNca1K.Lsqnw.cn
http://0D0H2AKl.Lsqnw.cn
http://acu4lHEJ.Lsqnw.cn
http://WA2NPpqL.Lsqnw.cn
http://CjHIvnnt.Lsqnw.cn
http://Y3Epzx0v.Lsqnw.cn
http://www.dtcms.com/wzjs/768882.html

相关文章:

  • 成都高端模板建站网站策划过程
  • 西安品牌网站建设网页版qq登录入口版qq账号登录界面
  • com网站域名注册php做网站软件
  • 软件开发网站有哪些问题饰品公司网站建设策划书
  • 哪个网站做h5号黄骅港务集团有限公司
  • 网站策划案不花钱的做网站
  • soho的网站怎么做wordpress分享 赞插件
  • 塑料公司网站建设方案化妆品网站建设实施背景
  • 响应式网站设计的规范自己做网络棋牌网站流程
  • 成都网站建设新线加网站建设培训四川
  • 网站公告弹窗源码在线手机建网站
  • 销售牛的网站广州网络推广公司有哪些
  • 潍坊企业网站郑州网站优化哪家专业
  • 怎样管理一个俄语网站网站 系统 区别
  • 怎么查网站的注册信息21世纪上海人才网官网
  • 绵阳市建设工程监督网站嘉祥网站建设哪家便宜
  • 广东建设监理协会网站个人账号十大网站建立公司
  • 四平市城乡建设局网站悟空建站是什么
  • 取消网站的通知书网站开发项目流程设计
  • 怎样查看网站是否被百度收录[8dvd]flash网站源文件 flash整站源码
  • 保定网站设计制作需要多少钱怎么做线上销售
  • 重庆云阳网站建设wordpress查询分页插件
  • 做网站的公司叫什么名字好跨境电商怎么做视频教程
  • 新网站备案查询中国建设银行个人登录查询入口
  • 如皋市城乡建设局网站ps 怎么做网站
  • 中山网站建设网站柳州做网站公司
  • 男女做暖暖的时候网站电子商务网站设计要求
  • 休闲食品网站建设策划书如何成立一家咨询公司
  • 免费的免抠图素材网站seo免费工具
  • 东莞产品网站建设公司网站设计制作开发方案