PAT (Advanced Level) 1074. Reversing Linked List (25)
简单题。
#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)的更多相关文章
- 【PAT甲级】1074 Reversing Linked List (25 分)
题意: 输入链表头结点的地址(五位的字符串)和两个正整数N和K(N<=100000,K<=N),接着输入N行数据,每行包括结点的地址,结点的数据和下一个结点的地址.输出每K个结点局部反转的 ...
- 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 ...
- 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 ...
- 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 ...
- PAT甲题题解-1074. Reversing Linked List (25)-求反向链表
题意说的很清楚了,这种题的话,做的时候最好就是在纸上自己亲手模拟一下,清楚一下各个指针的情况, 这样写的时候就很清楚各个指针变量保存的是什么值. PS:一次AC哈哈,所以说自己动手在纸上画画还是很有好 ...
- PAT甲级1074 Reversing Linked List (25分)
[程序思路] 先根据地址按顺序读入节点,入栈,当栈里的元素个数等于k时全部出栈,并按出栈顺序保存,最后若栈不为空,则全部出栈并按出栈的稀饭顺序保存,最后输出各节点 注意:输入的节点中有可能存在无用节点 ...
- 1074. Reversing Linked List (25)
模拟题,注意当k == 1 与 k == n时情况 #include <stdio.h> #include <string.h> #include <iostream&g ...
- PAT (Advanced Level) 1113. Integer Set Partition (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1110. Complete Binary Tree (25)
判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...
随机推荐
- javascript模板引擎template.render使用
<script type="text/javascript"> function test(){ //你的方法 } </script> 如上代码:通常我们见 ...
- shell变量的替换
1 shell变量基础shell变量是一种很“弱”的变量,默认情况下,一个变量保存一个串,shell不关心这个串是什么含义.所以若要进行数学运算,必须使用一些命令例如let.declare.expr. ...
- [转]关于Socket粘包问题
这两天看csdn有一些关于socket粘包,socket缓冲区设置的问题,发现自己不是很清楚,所以查资料了解记录一下: 一两个简单概念长连接与短连接:1.长连接 Client方与Server方先建立通 ...
- jquery:赋值
Jquery的赋值语句 $("#txtStyle").val(value); 获取操作: var val = $('#test').val(); --
- Ckeditor配置
配置参考文档,主要将ckeditor中的(adapters.images.lang.plugins.skins.themes.ckeditor.js.config.js.contents.css)解压 ...
- passwd总结
1.当前用户是root root用户修改密码 ,直接 passwd[不要输入当前用户密码] 如果修改其他用户密码,需要 passwd 用户名 如: passwd sc 短短的密码,如123也能通过,因 ...
- json的引号之伤
最近读他们的jquery解读的源码,由于版本不同,我可能看的是他们解读的1.7的,但是我本身运行的可能是1.9的,所以有些出处,但是中心思想不变,我有疑问的时候,直接debug,让例子自己走一遍,好处 ...
- git conflict
https://wiki.52north.org/bin/view/Documentation/ResolveMergeConflictsInGitEclipse Note that you can ...
- max_%_connection参数详解
对于连接数的设置,show variables里有三个参数可以对它进行控制,max_connections与max_user_connections以及max_connect_errors.下面对这三 ...
- 转 dos 下的 find 和 重定向
1.find /i "ora-" *.* > check.log 附录: 我对findstr是如此的依赖,以至于当我向各位讲解find命令的时候,我还得老老实实地在cmd窗口 ...