Simple question.
#include <cstdio>#include<cstring>#include<cmath>#include<vector>#include<map>#include<stack>#include<queue>#include<string>#include<algorithm>using namespacestd;Const intmaxn=100000+Ten;structnode{Charaddress[Ten]; Chardata[ -]; Charnext[Ten];} NODE[MAXN],TMP[MAXN],PRI[MAXN];intN,k;map<string,int>m;Charstadd[Ten];voidCopy (intAintb) {strcpy (Tmp[a]. ADDRESS,NODE[B]. Address); strcpy (Tmp[a]. DATA,NODE[B]. Data); strcpy (Tmp[a]. NEXT,NODE[B]. Next);}intMain () {scanf ("%s%d%d",stadd,&n,&k); M.clear (); for(intI=0; i<n; i++) {scanf ("%s%s%s", Node[i]. Address,node[i]. Data,node[i]. Next); M[node[i]. Address]=i; } intnow=M[stadd]; intkk=0; while(1) {Copy (Kk,now); if(strcmp ("-1", Node[now]. Next) = =0) Break; KK++; now=M[node[now]. Next]; } Now=0;intC=0; while(now<kk+1) { if(now+k-1<kk+1) { for(inti=now+k-1; i>=now; i--) {strcpy (Pri[c]. Address,tmp[i]. Address); strcpy (Pri[c]. Data,tmp[i]. Data); C++; } Now=now+K; } Else { for(intI=now; i<kk+1; i++) {strcpy (Pri[c]. Address,tmp[i]. Address); strcpy (Pri[c]. Data,tmp[i]. Data); C++; } Now=kk+1; } } for(intI=0; i<kk+1; i++) {printf ("%s%s", Pri[i]. Address,pri[i]. Data); if(i<kk+1-1) printf ("%s\n", pri[i+1]. Address); Elseprintf"-1\n"); } return 0;}
PAT (Advanced level) 1074. Reversing Linked List (25)