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 ...
随机推荐
- 计算mysql中某个字段某字符出现的次数,case when 和 截取字符的用法
select LENGTH(type) - LENGTH(replace(type,'_','')) as counts from sa_log_olap where type like 'XX_XX ...
- CSS实现各类分栏布局
在CSS中,实现分栏布局有两种方法.第一种方法是使用四种CSS定位选项(absolute .static.relative和fixed)中的绝对定位(absolute positioning),它可以 ...
- CentOS7系列--1.4CentOS7服务
CentOS7服务管理 1. 查看服务 1.1. 查看所有运行的服务 [root@centos7 ~]# systemctl -t service UNIT LOAD ACTIVE SUB DESCR ...
- 跨域调用报表展现页面的flash打印方法
环境说明: 项目的应用和润乾的报表应用分别部署在同一机器不同的web服务器上(IP相同,端口不同,项目的端口8080,报表应用的端口是6868). 在项目中的父页面通过iframe调用报表展现页 ...
- jsonp 返回以前必须要再转一次json
public static void main(String[] args) { String ajaxJsonStr = null; AjaxJson ajaxJson ...
- Pig group用法举例
group语句可以把具有相同键值的数据聚合在一起,与SQL中的group操作有着本质的区别,在SQL中group by字句创建的组必须直接注入一个或多个聚合函数.在Pig Latin中grou ...
- js 中文长字符截短&关键字符隐藏 自定义过滤器
两个非常简单的过滤器:隐藏关键字符和字符截短.同样也可以迁移到ng和原生js直接使用(去掉avalon.filters声明即可).后期还有不错的过滤器,还往这里面加 keyword:avalon,js ...
- CSS 小结笔记之浮动
在css中float是一个非常好用的属性,float最基本用法是用来做文字环绕型的样式的. 基本用法:float:left | right 例如 <!DOCTYPE html> <h ...
- Swiper-轮播图。
Swiper(Swiper master)是目前应用较广泛的移动端网页触摸内容滑动js插件,可以用来做轮播和滑动. 初始化 <!DOCTYPE html> <html> < ...
- [翻译] ZCSHoldProgress
ZCSHoldProgress 以下是使用效果: https://github.com/zshannon/ZCSHoldProgress "Your users be pressin' lo ...