A1074 Reversing Linked List (25分)未解决看懂

二、参考代码

#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    int first, k, n, sum = 0;
    cin >> first >> n >> k;
    int temp, data[100010], next[100010], list[100010], result[100010];
    for(int i = 0; i < n; i++){
        cin >> temp;
        cin >> data[temp] >> next[temp];
    }
    while(first != -1){
        list[sum++] = first;
        first = next[first];
    }
    for(int i = 0; i < sum; i++) result[i] = list[i];
    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;
}

原文地址:https://www.cnblogs.com/tsruixi/p/12257482.html

时间: 2024-10-07 12:20:32

A1074 Reversing Linked List (25分)未解决看懂的相关文章

浙大数据结构课后习题 练习二 7-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 elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4, you must output 4→3→2→1→5→6. Input Specification:

1074 Reversing Linked List (25分) 链表反转

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

【PAT甲级】1074 Reversing Linked List (25 分)

题意: 输入链表头结点的地址(五位的字符串)和两个正整数N和K(N<=100000,K<=N),接着输入N行数据,每行包括结点的地址,结点的数据和下一个结点的地址.输出每K个结点局部反转的链表. trick: 测试点6包含一些不在起点这条链表上的结点. 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;map<string,pair<int,string> >

PAT1074 Reversing Linked List (25)详细题解

02-1. Reversing Linked List (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6,

PAT 1074. Reversing Linked List (25)

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

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

02-线性结构1. Reversing Linked List (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→

1133 Splitting A Linked List (25 分)

1133 Splitting A Linked List (25 分) Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear before all of the non-negatives, and all the values in [0, K] appear before all those greater than K. Th

数据结构练习 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 elements on L. For example, given L being 1→2→3→4→5→6, if K = 3, then you must output 3→2→1→6→5→4; if K = 4, you must output 4→3→2→1→5→6. Input Specificat

1074. Reversing Linked List (25)

reverse 方法很好用 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K = 3, then yo