简单题。

#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. 微信接口开发1--向微信发送请求--获取access_token

    //随便放置一个php文件在服务器上.执行该方法--调用模拟get提交---到微信-->获得微信返回的access_token 不建议自己编写模拟get提交方法. 建议直接导入微信框架LaneW ...

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

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

  3. 解决“Xlib.h not found when building graphviz on Mac OS X 10.8”错误

    After installing XQuartz you may add a symlink to your X11 installation folder by just entering (安装X ...

  4. UIView animateWithDuration 使用详解

    在ios4.0及以后鼓励使用animateWithDuration方法来实现动画效果.当然,以往的begin/commit的方法依然使用,下面详细解释一下animateWithDuration的使用方 ...

  5. ecshop订单状态对应值详解

    ecshop的订单状态都是在ecs_order_info表中的字段里. 订单状态 未确认 取消 确认 已付款 配货中 已发货 已收货 退货 order_status 0 2 1 1 1 5 5 4 s ...

  6. [转载] 关于Windows Boot Manager、Bootmgfw.efi、Bootx64.efi、bcdboot.exe 的详解

    原帖: http://bbs.wuyou.net/forum.php?mod=viewthread&tid=303679 前言:1.本教程针对于UEFI启动来叙述的,根据普遍的支持UEFI的机 ...

  7. Java 类的加载过程(阿里面试题)

    问以下程序打印出什么内容: 问题及解析如下: /** * 加载方法不等于执行方法,初始化变量则会赋值 * 类加载顺序应为 加载静态方法-初始化静态变量-执行静态代码块 * 实例化时 先加载非静态方法- ...

  8. Got a packet bigger than ‘max_allowed_packet’ bytes的解决方法

    在使用 longtext 类型执行数据录入时,有时会抛出这个异常,从字面理解就是当前包大小超过 mysql 系统设置的包大小无法执行操作. 解释一下包大小这个东西:简单来说就是mysql把当前执行的m ...

  9. Java Concurrent Topics

    To prevent Memory Consistency Errors(MCEs), it is good practice to specify synchronized class specif ...

  10. 函数FindFirstFile

    文件查找 Struct Lnode{ Char table[256];         //保存文件夹名 Struct Lnode*next; } 加文件夹入链表 Lnode *newList; Vo ...