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分)的更多相关文章

  1. PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)

    1032 Sharing (25 分)   To store English words, one method is to use linked lists and store a word let ...

  2. 【PAT甲级】1032 Sharing (25 分)

    题意: 输入两个单词的起始地址和一个正整数N(<=1e5),然后输入N行数据,每行包括一个五位数的字母地址,字母和下一个字母的地址.输出这两个单词的公共后缀首字母的地址,若无公共后缀则输出-1. ...

  3. 1032 Sharing (25分)(数组链表)

    To store English words, one method is to use linked lists and store a word letter by letter. To save ...

  4. PAT 1032 Sharing (25分) 从自信到自闭

    题目 To store English words, one method is to use linked lists and store a word letter by letter. To s ...

  5. 【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 ...

  6. 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 ...

  7. 1032. Sharing (25) -set运用

    题目如下: To store English words, one method is to use linked lists and store a word letter by letter. T ...

  8. 1032. Sharing (25)

    To store English words, one method is to use linked lists and store a word letter by letter. To save ...

  9. PAT甲题题解-1032. Sharing (25)-链表水题

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

随机推荐

  1. [PAT] A1020 Tree Traversals

    [题目] distinct 不同的 postorder 后序的 inorder 中序的 sequence 顺序:次序:系列 traversal 遍历 题目大意:给出二叉树的后序遍历和中序遍历,求层次遍 ...

  2. P1462 通往奥格瑞玛的道路【二分+Dij】

    P1462 通往奥格瑞玛的道路 提交 29.89k 通过 6.88k 时间限制 1.00s 内存限制 125.00MB 题目提供者gconeice 难度提高+/省选- 历史分数100 提交记录 查看题 ...

  3. html5的页面在IOS中,按钮 变成圆角怎么办?

      在button的css 中添加: -webkit-appearance: none;     border: none;     border-radius: 0; ok 的啦   文章来源:刘俊 ...

  4. 2级搭建类203-Oracle 19c SI ASM 静默搭建(OEL7.7)

    Oracle 19c 单实例 ASM UDEV 方式在 OEL 7.7 上的安装

  5. 0级搭建类011-Oracle Linux 7.x安装(OEL 7.7) 公开

    项目文档引子系列是根据项目原型,制作的测试实验文档,目的是为了提升项目过程中的实际动手能力,打造精品文档AskScuti. 项目文档引子系列目前不对外发布,仅作为博客记录.如学员在实际工作过程中需提前 ...

  6. [Python]find_all函数 2020.2.7

    .find_all(name,attrs,recursive,string,**kwargs) name:对标签名称的检索字符串attrs:对标签属性值的检索字符串,可标注属性检索recursive: ...

  7. Networking POJ - 1287 最小生成树板子题

    #include<iostream> #include<algorithm> using namespace std; const int N=1e5; struct edge ...

  8. Struts2学习-jsp中超链接传参问题

    今天在学习过程中对struts2中超链接的传参问题产生了一些疑惑,不明白jsp中的超链接如何将参数传到Action方法中去的. <s:iterator value="categorys ...

  9. numpy学习(四)

    练习篇(Part 4) 41. How to sum a small array faster than np.sum? (★★☆) arr = np.arange(10) print(np.add. ...

  10. nginx配置之后接口状态200,但是无返回数据问题小记

    nginx配置可能有问题.导致nginx不能解析PHP文件,检测nginx里对于php的配置信息. location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; f ...