简单题。

#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. Chapter 1 First Sight——33

    At that moment, the bell rang loudly, making me jump, and Edward Cullen was out of his seat. 在这个时候,铃 ...

  2. Centos更换yum源,安装ssh server

    先连上网,然后更换yum源 1. 新建的用户没有sudo权限,所以首先切换到root用户su -输入密码 2. 备份之前的yum源mv /etc/yum.repos.d/CentOS-Base.rep ...

  3. JavaScript高级程序设计:第二十一章

    第二十一章 Ajax与Comet 一.XMLHttpRequest对象 1.XHT的用法 在使用XHR对象时,要调用的第一个方法时open( ),它接受3个参数:要发送的请求的类型.请求的URL和表示 ...

  4. SNMP学习之结构体snmp_secmod_def

    此结构体中定义了各个回调函数,在函数init_ksm(E:\code\net-snmp-5.4.2.1\snmplib)中进行了初始化. void init_ksm(void) { struct sn ...

  5. webapp前端开发软键盘与position:fixed为我们带来的不便

    前提:我们考虑兼容的环境为android和ios两种智能手机 兼容环境测试结果显示android的表现明显好于ios,ios手机在软键盘呼起收起时存在着很严重的兼容性问题 场景展示: 页面正常状态 软 ...

  6. iOS中date和string的相互转换

    必须知道的内容 G: 公元时代,例如AD公元     yy: 年的后2位     yyyy: 完整年     MM: 月,显示为1-12     MMM: 月,显示为英文月份简写,如 Jan      ...

  7. Linux 系统监控

    *lsof 列出打开的文件 常用   lsof -i:8080*htop进程监控iotop(bugs)iptraf实时局域网IP监控psacct 监视用户活动monit Linux进程和服务监控工具* ...

  8. MyEclipse 2015 运行tomcat 内存溢出的解决方法

    内存溢出错误: 2016-3-16 11:19:55 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() ...

  9. Jquery 实现原理之 Ajax

    一:Jquery Ajax底层接口有:$.ajaxPrefilters.$.ajaxTransport.$.ajaxSettings.$ajaxSetup.$ajaxSettings; 其中$.aja ...

  10. sed awk 小例

    实现数据库批量更新与回滚 create database awktest; use awktest create table user(    id int unsigned not null uni ...