pat 1025 反转链表
生活随笔
收集整理的這篇文章主要介紹了
pat 1025 反转链表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
注意到地址是一些數字,所以直接用int存了,這樣就可以不用map了。
機制的學叔。我就是個逗逼。
#include <stdio.h>int node[100000][3]; int list[100000];int main() {int n, k, start;while(scanf("%d%d%d", &start, &n, &k) != EOF){for(int i = 0; i < n; i++){int addr, data, next;scanf("%d%d%d", &addr, &data, &next);node[addr][0] = data, node[addr][1] = next;}list[0] = start;int last =start;int count = 1;for(int i = 1; i < n; i++){node[last][2] = last;last = list[i] = node[last][1];count++;if(node[last][1] == -1)break;}int s,e;s = 0;e = s + k;while(e <= count && e > s){for(int j = e-1; j >= s; j--){if(j == k-1)printf("%05d %d ", list[j], node[list[j]][0]);else printf("%05d\n%05d %d ", list[j], list[j], node[list[j]][0]);}s = e;e = s+k;}for(int j = s; j < count; j++){if(j == 0)printf("%05d %d ", list[j], node[list[j]][0]);elseprintf("%05d\n%05d %d ", list[j], list[j], node[list[j]][0]);}printf("-1\n");}return 0; }總結
以上是生活随笔為你收集整理的pat 1025 反转链表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu 1806线段树 区间合并
- 下一篇: poj 2352 线段树