1032 Sharing (25分)
1032 Sharing (25分)
题目
思路
定义map存储所有的<地址1,地址2>
第一set存放单词1的所有地址(通过查找map)
通过单词二的首地址,结合map,然后在set中查找是否存在,如果存在就是所求的地址,没有就是-1
注意点
无
代码
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
int main() {
int n;
string a, b;
cin>>a>>b>>n;
map<string, string> common;
set<string> c1;
for(int i=0;i<n;i++){
string s1, s2;
char ch;
cin>>s1>>ch>>s2;
common[s1] = s2;
}
string _a = a;
c1.insert(_a);
while((_a = common[_a]) != "-1"){
c1.insert(_a);
}
c1.insert(_a);
string _b = b;
if(c1.find(_b) != c1.end()){
printf("%s", _b.c_str());
return 0;
}
while((_b = common[_b]) != "-1"){
if(c1.find(_b) != c1.end()){
printf("%s", _b.c_str());
return 0;
}
}
printf("-1");
}
1032 Sharing (25分)的更多相关文章
- PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)
1032 Sharing (25 分) To store English words, one method is to use linked lists and store a word let ...
- 【PAT甲级】1032 Sharing (25 分)
题意: 输入两个单词的起始地址和一个正整数N(<=1e5),然后输入N行数据,每行包括一个五位数的字母地址,字母和下一个字母的地址.输出这两个单词的公共后缀首字母的地址,若无公共后缀则输出-1. ...
- 1032 Sharing (25分)(数组链表)
To store English words, one method is to use linked lists and store a word letter by letter. To save ...
- PAT 1032 Sharing (25分) 从自信到自闭
题目 To store English words, one method is to use linked lists and store a word letter by letter. To s ...
- 【PAT】1032 Sharing (25)(25 分)
1032 Sharing (25)(25 分) To store English words, one method is to use linked lists and store a word l ...
- PAT甲 1032. Sharing (25) 2016-09-09 23:13 27人阅读 评论(0) 收藏
1032. Sharing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To store Engl ...
- 1032. Sharing (25) -set运用
题目如下: To store English words, one method is to use linked lists and store a word letter by letter. T ...
- 1032. Sharing (25)
To store English words, one method is to use linked lists and store a word letter by letter. To save ...
- PAT甲题题解-1032. Sharing (25)-链表水题
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
随机推荐
- 【巨杉数据库SequoiaDB】24 Hours , 数据库研发实录
出场人物: 08:10 小H,是巨杉数据库引擎研发的一名工程师.7:20 天还蒙蒙亮,小H就起床了,点亮了心爱的光剑,开始了新的一天. 在08:10时候,他已经洗漱完,锻炼好身体,倒好 ...
- ansible-yaml语法
1. 基础语法 - yaml结果通过空格来展示 - 数组使用"- "来表示 //注意:-后边要有一个空格 - 键值对使用": "来表示 //注意::后边要有一个 ...
- flex 属性
一.flex-direction(元素排列方向) 1.flex-direction:row://从左到右排列 2.flex-direction:column://从上往下排列 二.flex-wrap( ...
- 关于SkinTextBox中SkinTxt的事件使用
SkinTxt的事件中的事件不能像一般的事件那样在属性中直接双击生成,它里面的事件都需要进行一定的转换间接使用,具体用法如下: 1.手动编写事件需要做的操作的方法 public void txtCod ...
- python3包、模块、类、方法的认识
包>>模块>>类>> 函数 包:就是一个目录,import time from+import导入包中的部分模块 直接到类 from budaoguan.common ...
- (备份)找回 Chrome 配置
C:\Users\xiaogezi.cn\AppData\Local\Google\Chrome\User Data\Default\ 将 Preferences 文件复制到别的地方,用于备份: 将 ...
- (三)运用Python模块和包
1 引言 为了能够在Python项目中高效地运用Python模块和包,我们需要进一步地来了解它们是如何在Python项目中进行定义.使用和工作的. 2 Python模块和包 Python模块和包的基本 ...
- [ZJOI2008] 生日聚会 - dp
共有\(n\)个男孩与\(m\)个女孩打算坐成一排.对于任意连续的一段,男孩与女孩的数目之差不超过 \(k\).求方案数. \(n,m \leq 150, k \leq 20\) Solution 设 ...
- 白面系列 nginx
Nginx == engine x. nginx就是一个服务器.主要提供web服务.负载均衡(反向代理).web缓存等服务. nginx ≈ apache,但nginx是轻量级的高性能高并发的服务器. ...
- ubuntu 安装 lnmp 参考
暂时参考 https://blog.csdn.net/weixin_36025897/article/details/81417458 https://www.jianshu.com/p/37cacd ...