【PAT甲级】1097 Deduplication on a Linked List (25 分)
题意:
输入一个地址和一个正整数N(<=100000),接着输入N行每行包括一个五位数的地址和一个结点的值以及下一个结点的地址。输出除去具有相同绝对值的结点的链表以及被除去的链表(由被除去的结点组成的链表)。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int nex[],val[];
vector<pair<int,int> >ans,ans2;
int vis[];
int main(){
//ios::sync_with_stdio(false);
//cin.tie(NULL);
//cout.tie(NULL);
int s,n;
cin>>s>>n;
for(int i=;i<=n;++i){
int x,y,z;
cin>>x>>y>>z;
nex[x]=z;
val[x]=y;
}
while(s!=-){
if(vis[abs(val[s])]){
ans2.push_back({s,val[s]});
s=nex[s];
continue;
}
ans.push_back({s,val[s]});
vis[abs(val[s])]=;
s=nex[s];
}
for(int i=;i<ans.size();++i){
printf("%05d %d ",ans[i].first,ans[i].second);
if(i<ans.size()-)
printf("%05d\n",ans[i+].first);
else
printf("-1\n");
}
for(int i=;i<ans2.size();++i){
printf("%05d %d ",ans2[i].first,ans2[i].second);
if(i<ans2.size()-)
printf("%05d\n",ans2[i+].first);
else
printf("-1\n");
}
return ;
}
【PAT甲级】1097 Deduplication on a Linked List (25 分)的更多相关文章
- PAT甲级——1097 Deduplication on a Linked List (链表)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91157982 1097 Deduplication on a L ...
- PAT Advanced 1097 Deduplication on a Linked List (25) [链表]
题目 Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplica ...
- PAT甲级:1066 Root of AVL Tree (25分)
PAT甲级:1066 Root of AVL Tree (25分) 题干 An AVL tree is a self-balancing binary search tree. In an AVL t ...
- PAT (Advanced Level) Practise - 1097. Deduplication on a Linked List (25)
http://www.patest.cn/contests/pat-a-practise/1097 Given a singly linked list L with integer keys, yo ...
- PAT甲级题解-1097. Deduplication on a Linked List (25)-链表的删除操作
给定一个链表,你需要删除那些绝对值相同的节点,对于每个绝对值K,仅保留第一个出现的节点.删除的节点会保留在另一条链表上.简单来说就是去重,去掉绝对值相同的那些.先输出删除后的链表,再输出删除了的链表. ...
- PAT甲级——A1097 Deduplication on a Linked List
Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated ...
- PAT (Advanced Level) 1097. Deduplication on a Linked List (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- 1097. Deduplication on a Linked List (25)
Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated ...
- PAT 甲级 1002 A+B for Polynomials (25 分)
1002 A+B for Polynomials (25 分) This time, you are supposed to find A+B where A and B are two polyno ...
随机推荐
- PP: Data-driven classification of residential energy consumption patterns by means of functional connectivity networks
Purpose Implement a good user aggregation and classification. or to assess the interrelation pattern ...
- Paper: A Novel Time Series Forecasting Method Based on Fuzzy Visibility Graph
Problem define a fuzzy visibility graph (undirected weighted graph), then give a new similarity meas ...
- Python记
在企业应用领域,Java或C#都是不错的选择.
- django 完成登录功能
啃了几天文档,感觉能理解了这个框架,但是真的下手的时候真的不知道从何开始. orm即Object-Relationl Mapping,看这名字就是操作数据库的,用过ssm,不过django操作数据库是 ...
- make && make install
./configure --prefix= /usr/local/python3.6.6 make && make install prefix=/usr/local/pyth ...
- Oracle 11g安装 —— Oracle Database 11g Release2 for Windows(x64)
文章来自:https://blog.csdn.net/IT_xiao_guang_guang/article/details/104422421 下面是我的Oracle 11g安装过程,希望可以帮到正 ...
- Json.Net的介绍与简单实用(兼容2.0/3.0/3.5/4.5/RT)
本文的前提是你已经熟悉Json,如果您还不知道什么是Json是什么,请自行查看维基百科. 一.Json.Net是什么? Json.Net是一个读写Json效率比较高的.Net框架.Json.Net 使 ...
- C++-POJ1067-取石子游戏
//(ak,bk)=([k*(1+sqrt(5))/2],[k*(1+sqrt(5))/2]+k)=(ak,ak+k) #include <cstdio> double sqrt5=2.2 ...
- 题解【2.23考试T3】val
3. val[题目描述] 这是一道传统题,源代码的文件名为 val.cpp/c/pas. 有一个值初始为 0,接下来 n 次你可以令其在之前基础上+2 或+1 或-1.你需要保证,这个值在整个过程中达 ...
- 关于Vector3.forward和Transform.forward
在Unity中有两个forward,一个是Transform.forward一个是Vector3.forward. 对于Vector3来说,它只是缩写.没有其它任何含义. Vector3.forwar ...