简单题。

#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. CATransform3D的使用以及各个参数的含义

    1. 缩放 CABasicAnimation *theAnimation=[CABasicAnimation animationWithKeyPath:@"transform"]; ...

  2. 在centos中部署jenkins

    在centos中部署jenkins,需要的环境:安装jdk,Apache-tomcat 这两步我前面文章里已写,再次忽略 到官网下载最新的jenkins 我这里的是  jenkins.war 把该文件 ...

  3. 这种方法在受到.NET版本和访问注册表权限时,是最佳解决方案,虽然代码看起来很多,不过下面的类直接拿走用就可以了。

    public class FileContentType  {      private static IDictionary<string, string> _mappings = ne ...

  4. Redis中connect和pconnect的区别

    首先先介绍下connect和pconnect的区别.connect:脚本结束之后连接就释放了. pconnect:脚本结束之后连接不释放,连接保持在php-fpm进程中.所以使用pconnect代替c ...

  5. SCP测试服务器的上行/下行带宽

    SCP测试服务器的上行/下行带宽,这个咋弄呢?有时间再研究一下.

  6. Hibernate 系列教程4-单向多对一

    项目图片 hibernate.cfg.xml <mapping resource="com/jege/hibernate/one/way/manytoone/User.hbm.xml& ...

  7. HDU 5234 Happy birthday 动态规划(三维数组)

    题目大意:过生日,有一个N*M的表格,每个位置都有一块一定重量的蛋糕你可以选择吃完或者不吃,从(1,1)走到(n,m),每次只能向右走或向下走,最多能吃k重量的蛋糕.问你最多能吃多少蛋糕. 题目思路: ...

  8. 一个经典的PHP验证码类分享

    我们通过PHP的GD库图像处理内容,设计一个验证码类Vcode.将该类声明在文件vcode.class.php中,并通过面向对象的特性将一些实现 的细节封装在该类中.只要在创建对象时,为构造方法提供三 ...

  9. Jquery的parent和parents(找到某一特定的祖先元素)

    关于Jquery的parent和parents parent是指取得一个包含着所有匹配元素的唯一父元素的元素集合.parents则是取得一个包含着所有匹配元素的祖先元素的元素集合(不包含根元素).可以 ...

  10. CodeIgniter 如何去掉 Index.php

    步骤; 1.打开你的WEB服务器的httpd.conf文件. 2.找到LoadModule rewrite_module modules/mod_rewrite.so这行,把该行前的#去掉.保存该文件 ...