1032 Sharing (25分)

题目

思路

定义map存储所有的<地址1,地址2>

第一set存放单词1的所有地址(通过查找map)

通过单词二的首地址,结合map,然后在set中查找是否存在,如果存在就是所求的地址,没有就是-1

注意点

代码

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<algorithm>
  5. #include<vector>
  6. #include<set>
  7. #include<string>
  8. #include<map>
  9. #include<queue>
  10. #include<stack>
  11. #include<iostream>
  12. using namespace std;
  13. int main() {
  14. int n;
  15. string a, b;
  16. cin>>a>>b>>n;
  17. map<string, string> common;
  18. set<string> c1;
  19. for(int i=0;i<n;i++){
  20. string s1, s2;
  21. char ch;
  22. cin>>s1>>ch>>s2;
  23. common[s1] = s2;
  24. }
  25. string _a = a;
  26. c1.insert(_a);
  27. while((_a = common[_a]) != "-1"){
  28. c1.insert(_a);
  29. }
  30. c1.insert(_a);
  31. string _b = b;
  32. if(c1.find(_b) != c1.end()){
  33. printf("%s", _b.c_str());
  34. return 0;
  35. }
  36. while((_b = common[_b]) != "-1"){
  37. if(c1.find(_b) != c1.end()){
  38. printf("%s", _b.c_str());
  39. return 0;
  40. }
  41. }
  42. printf("-1");
  43. }

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. 【巨杉数据库SequoiaDB】24 Hours , 数据库研发实录

    出场人物: ​ ​ 08:10 ​ 小H,是巨杉数据库引擎研发的一名工程师.7:20 天还蒙蒙亮,小H就起床了,点亮了心爱的光剑,开始了新的一天. ​ 在08:10时候,他已经洗漱完,锻炼好身体,倒好 ...

  2. ansible-yaml语法

    1. 基础语法 - yaml结果通过空格来展示 - 数组使用"- "来表示 //注意:-后边要有一个空格 - 键值对使用": "来表示 //注意::后边要有一个 ...

  3. flex 属性

    一.flex-direction(元素排列方向) 1.flex-direction:row://从左到右排列 2.flex-direction:column://从上往下排列 二.flex-wrap( ...

  4. 关于SkinTextBox中SkinTxt的事件使用

    SkinTxt的事件中的事件不能像一般的事件那样在属性中直接双击生成,它里面的事件都需要进行一定的转换间接使用,具体用法如下: 1.手动编写事件需要做的操作的方法 public void txtCod ...

  5. python3包、模块、类、方法的认识

    包>>模块>>类>> 函数 包:就是一个目录,import time from+import导入包中的部分模块 直接到类 from budaoguan.common ...

  6. (备份)找回 Chrome 配置

    C:\Users\xiaogezi.cn\AppData\Local\Google\Chrome\User Data\Default\ 将 Preferences 文件复制到别的地方,用于备份: 将 ...

  7. (三)运用Python模块和包

    1 引言 为了能够在Python项目中高效地运用Python模块和包,我们需要进一步地来了解它们是如何在Python项目中进行定义.使用和工作的. 2 Python模块和包 Python模块和包的基本 ...

  8. [ZJOI2008] 生日聚会 - dp

    共有\(n\)个男孩与\(m\)个女孩打算坐成一排.对于任意连续的一段,男孩与女孩的数目之差不超过 \(k\).求方案数. \(n,m \leq 150, k \leq 20\) Solution 设 ...

  9. 白面系列 nginx

    Nginx == engine x. nginx就是一个服务器.主要提供web服务.负载均衡(反向代理).web缓存等服务. nginx ≈ apache,但nginx是轻量级的高性能高并发的服务器. ...

  10. ubuntu 安装 lnmp 参考

    暂时参考 https://blog.csdn.net/weixin_36025897/article/details/81417458 https://www.jianshu.com/p/37cacd ...