PAT02-线性结构3 Reversing Linked List
题目: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的更多相关文章
- pat02-线性结构1. Reversing Linked List (25)
02-线性结构1. Reversing Linked List (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, ...
- 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 ...
- 02-线性结构3 Reversing Linked List
02-线性结构3 Reversing Linked List (25分) 时间限制:400ms 内存限制:64MB 代码长度限制:16kB 判题程序:系统默认 作者:陈越 单位:浙江大学 http ...
- 02-线性结构2 Reversing Linked List
由于最近学的是线性结构,且因数组需开辟的空间太大.因此这里用的是纯链表实现的这个链表翻转. Given a constant K and a singly linked list L, you are ...
- 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 ...
- 数据结构练习 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 基于jQuery的软键盘
基于jQuery的软键盘 前些天写了一个基于基于jQuery的数字键盘,今天给大家带来一个基于jQuery的全字母键盘插件(支持全字母大小写切换,数字输入,退格清除,关闭功能,可调整大小和键盘位置 ...
- cf605D. Board Game(BFS 树状数组 set)
题意 题目链接 有\(n\)张牌,每张牌有四个属性\((a, b, c, d)\),主人公有两个属性\((x, y)\)(初始时为(0, 0)) 一张牌能够被使用当且仅当\(a < x, b & ...
- 14:求10000以内n的阶乘
14:求10000以内n的阶乘 查看 提交 统计 提问 总时间限制: 5000ms 内存限制: 655360kB 描述 求10000以内n的阶乘. 输入 只有一行输入,整数n(0<=n< ...
- webapi 后台跳转 后台输出html和script
1.跳转 [HttpGet]public HttpResponseMessage LinkTo(){ HttpResponseMessage resp = new HttpResponseMessag ...
- Linux Windows平台添加pip源
直接应用 pip3 install django -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com ...
- Python redis交互
1.首先安装模块 pip3 install redis 2.代码模板如下: from redis import StrictRedis if __name__ == '__main__': # 设置连 ...
- Python 中单双引号
TODO, 在python中, 其实单双引号还是有分别的, 具体是什么?
- 给category添加基本数据类型属性
给category添加基本数据类型属性 说明 通常,我们添加属性都是通过对象扩展来实现的,其实,我们也可以用runtime来添加基本数据类型的属性 源码 // // UIView+AnimationP ...
- 北美Developer生存发展攻略
http://www.followmedoit.com/bbs/forum.php?mod=viewthread&tid=49&extra=page%3D1 在北美,做PM不易,而做D ...
- Linux 系统的磁盘设备_【all】
磁盘 ->RAID ->分区 ->格式化 ->挂载 基本的框架 a.硬盘的外部以及内部硬件结构,工作原理和读写原理b.RAID的划分(一块盘划分为一块或者多块的小虚拟磁盘,可以 ...