简单题。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std; const int maxn=+; struct Node
{
char Address[];
char Data[];
char Next[];
} node[maxn],tmp[maxn],pri[maxn]; int n,k;
map<string,int>m;
char StAdd[]; void Copy(int a,int b)
{
strcpy(tmp[a].Address,node[b].Address);
strcpy(tmp[a].Data,node[b].Data);
strcpy(tmp[a].Next,node[b].Next);
} int main()
{
scanf("%s%d%d",StAdd,&n,&k);
m.clear();
for(int i=; i<n; i++)
{
scanf("%s%s%s",node[i].Address,node[i].Data,node[i].Next);
m[node[i].Address]=i;
} int now=m[StAdd];
int kk=;
while()
{
Copy(kk,now);
if(strcmp("-1",node[now].Next)==) break;
kk++;
now=m[node[now].Next];
} now=; int c=;
while(now<kk+)
{
if(now+k-<kk+)
{
for(int i=now+k-; i>=now; i--)
{
strcpy(pri[c].Address,tmp[i].Address);
strcpy(pri[c].Data,tmp[i].Data);
c++;
}
now=now+k;
}
else
{
for(int i=now; i<kk+; i++)
{
strcpy(pri[c].Address,tmp[i].Address);
strcpy(pri[c].Data,tmp[i].Data);
c++;
}
now=kk+;
}
} for(int i=; i<kk+; i++)
{
printf("%s %s ",pri[i].Address,pri[i].Data);
if(i<kk+-) printf("%s\n",pri[i+].Address);
else printf("-1\n");
}
return ;
}

PAT (Advanced Level) 1074. Reversing Linked List (25)的更多相关文章

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

    题意: 输入链表头结点的地址(五位的字符串)和两个正整数N和K(N<=100000,K<=N),接着输入N行数据,每行包括结点的地址,结点的数据和下一个结点的地址.输出每K个结点局部反转的 ...

  2. PAT 甲级 1074 Reversing Linked List (25 分)(链表部分逆置,结合使用双端队列和栈,其实使用vector更简单呐)

    1074 Reversing Linked List (25 分)   Given a constant K and a singly linked list L, you are supposed ...

  3. PAT Advanced 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 e ...

  4. 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 elem ...

  5. PAT甲题题解-1074. Reversing Linked List (25)-求反向链表

    题意说的很清楚了,这种题的话,做的时候最好就是在纸上自己亲手模拟一下,清楚一下各个指针的情况, 这样写的时候就很清楚各个指针变量保存的是什么值. PS:一次AC哈哈,所以说自己动手在纸上画画还是很有好 ...

  6. PAT甲级1074 Reversing Linked List (25分)

    [程序思路] 先根据地址按顺序读入节点,入栈,当栈里的元素个数等于k时全部出栈,并按出栈顺序保存,最后若栈不为空,则全部出栈并按出栈的稀饭顺序保存,最后输出各节点 注意:输入的节点中有可能存在无用节点 ...

  7. 1074. Reversing Linked List (25)

    模拟题,注意当k == 1 与 k == n时情况 #include <stdio.h> #include <string.h> #include <iostream&g ...

  8. PAT (Advanced Level) 1113. Integer Set Partition (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. PAT (Advanced Level) 1110. Complete Binary Tree (25)

    判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...

随机推荐

  1. vc里面怎样实现对话框之间传递变量的值

    Dialog1的类名是CDialog1, 头文件是dialog1.h.里有成员变量CString str1, str2;Dialog2的类名是CDialog2, 头文件是dialog2.h.里有成员变 ...

  2. Chapter 2 Open Book——16

    By Friday I was perfectly comfortable entering my Biology class, nolonger worried that Edward would ...

  3. JVM调优总结-调优方法

    JVM调优工具 Jconsole,jProfile,VisualVM Jconsole : jdk自带,功能简单,但是可以在系统有一定负荷的情况下使用.对垃圾回收算法有很详细的跟踪 JProfiler ...

  4. Centos中压缩(zip)和解压(unzip)命令

    摘自:http://liuzhichao.com/p/681.html 1.我下载了一个yasuo.zip文件,想解压缩: # unzip yasuo.zip 2.我当前目录下有abc1.zip,ab ...

  5. golang vs java

    http://programmers.stackexchange.com/questions/83780/how-fast-can-go-go In terms of language design, ...

  6. git简单使用教程

    git 的基本使用指令 我们先来简单熟悉一下 git 的简单使用的指令, 作为最基本的 git 指令一定要熟悉 12345678910111213141516171819202122232425262 ...

  7. cmd命令行查看当前系统版本和版本是32位还是64位

  8. $scope

    $scope.aaa = 3; $scope.bbb = 4; $scope.aaa = $scope.bbb; //这只是简单的赋值 $scope.bbb = 5; 输出 $scope.aaa为4 ...

  9. 几种JAVA加密算法

    转自:http://www.cnblogs.com/mycodelife/archive/2009/04/22/1441624.html

  10. 转 excel表怎么自动分列

    http://jingyan.baidu.com/article/656db918fc3501e380249c53.html