题目:https://pintia.cn/problem-sets/1010070491934568448/problems/1037889290772254722

先是看了牛客(https://www.nowcoder.com/questionTerminal/5f44c42fd21a42b8aeb889ab83b17ad0)的几个代码,觉得很复杂,发现问题很多,用python写内容真的不容易

后来找到一个相当简洁的代码,真心点赞,地址:https://www.liuchuo.net/archives/463

#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int first, k, n, temp;
cin >> first >> n >> k;
int data[], next[], list[];
for (int i = ; i < n; i++) {
cin >> temp;
cin >> data[temp] >> next[temp];
}
int sum = ;//不一定所有的输入的结点都是有用的,加个计数器
while (first != -) {
list[sum++] = first;
first = next[first];
}
for (int i = ; i < (sum - sum % k); i += k)
reverse(begin(list) + i, begin(list) + i + k);
for (int i = ; i < sum - ; i++)
printf("%05d %d %05d\n", list[i], data[list[i]], list[i + ]);
printf("%05d %d -1", list[sum - ], data[list[sum - ]]);
return ;
}

反思总结:

1.对库的函数不是很熟悉。   打印常用的库,和对应的函数,最好背诵一下

2.对c++,不熟练,要常练习

PAT02-线性结构3 Reversing Linked List的更多相关文章

  1. pat02-线性结构1. Reversing Linked List (25)

    02-线性结构1. Reversing Linked List (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, ...

  2. 02-线性结构3 Reversing Linked List(25 point(s)) 【链表】

    02-线性结构3 Reversing Linked List(25 point(s)) Given a constant K and a singly linked list L, you are s ...

  3. 02-线性结构3 Reversing Linked List

    02-线性结构3 Reversing Linked List   (25分) 时间限制:400ms 内存限制:64MB 代码长度限制:16kB 判题程序:系统默认 作者:陈越 单位:浙江大学 http ...

  4. 02-线性结构2 Reversing Linked List

    由于最近学的是线性结构,且因数组需开辟的空间太大.因此这里用的是纯链表实现的这个链表翻转. Given a constant K and a singly linked list L, you are ...

  5. PTA 02-线性结构3 Reversing Linked List (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/664 5-2 Reversing Linked List   (25分) Given a ...

  6. 数据结构练习 02-线性结构2. Reversing Linked List (25)

    Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elem ...

  7. 02-线性结构3 Reversing Linked List (25 分)

    Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elem ...

  8. 02-线性结构3 Reversing Linked List (25 分)

    Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elem ...

  9. 02-线性结构3 Reversing Linked List

    题目 Sample Input: 00100 6 4 00000 4 99999 00100 1 12309 68237 6 -1 33218 3 00000 99999 5 68237 12309 ...

随机推荐

  1. UVA11624(KB1-J)

    Fire! Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of ...

  2. 翻译 – CSS3 Backgrounds相关介绍——张鑫旭

    —————以下为翻译内容—————- CSS2.1中有5个background属性可以用来控制元素的背景.这5个属性是: background-color background-image backg ...

  3. oracel存储过程编写 以及plsql存储过程的debug

    1.语法: create or replace procedure messagebackup_createTable       //此处存储过程名称不能超过30个字符 as  tableName ...

  4. 什么是Github?

    初识Github GitHub 是程序员的必备技能 1.什么是Github? 确切的说 GitHub 是一家公司,位于旧金山,由 Chris Wanstrath, PJ Hyett 与 Tom Pre ...

  5. Android属性动画的监听事件

    整体很简单,直接上代码吧.activity_main.xml: <?xml version="1.0" encoding="utf-8"?> < ...

  6. frame shiro 概述

    权限管理 权限管理包括用户身份认证和授权两部分,简称认证授权. 身份认证包括用户口令登陆.指纹验证.刷卡等方式. 授权即访问控制,控制谁能访问哪些资源,主体身份认证后分配权限以访问自己可以访问的资源. ...

  7. IIS测试环境搭建

    1.控制面板->程序->程序和功能->打开或关闭Windows功能->Internet信息服务->Web管理工具,打开如下服务: 2.打开IIS管理器 2.1检查.net ...

  8. Eigen学习笔记2-Matrix类

    在Eigen中,所有的矩阵Matrix和向量Vector都是由Matrix类构造的.向量只不过是矩阵的特殊形式,只有一列(列向量)或者一行. Matrix模板类有6个参数,其中前三个参数是必须的.前三 ...

  9. 如何监视和更新 Azure 中的 Linux 虚拟机

    为确保 Azure 中的虚拟机 (VM) 正常运行,可以查看启动诊断.性能指标,并管理程序包更新. 本教程介绍如何执行下列操作: 在 VM 上启用启动诊断 查看启动诊断 在 VM 上启用诊断扩展 基于 ...

  10. ExpressRoute 合作伙伴和对等位置

    本文中的表格提供有关 ExpressRoute 连接提供商.ExpressRoute 地理覆盖范围.通过 ExpressRoute 支持的 Azure 服务以及 ExpressRoute 系统集成商 ...