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. windows命令提示符常用命令

    1.进入某个磁盘 c:  进入c盘 d: 进入d盘 2.返回到根目录 cd \ 3.查看当钱路径下的文件和文件夹 dir 4.清空窗口内容 cls 5.关闭窗口 exit 6.返回上一级目录 cd . ...

  2. latex技巧:弧AB

    \usepackage{yhmath} $\wideparen{ABCDEFG}$

  3. springboot~集成DataSource 与 Druid监控配置

    介绍 Druid首先是一个数据库连接池.Druid是目前最好的数据库连接池,在功能.性能.扩展性方面,都超过其他数据库连接池,Druid已经在阿里巴巴部署了超过600个应用,经过一年多生产环境大规模部 ...

  4. 我的第一个原生Web Components——滑块(SingleSlider)

    写着写着,就会跑偏,没错又走上了一个岔道……就是不知道这条岔道以后会不会越来越宽,有的说他是未来,有的说…… 这里不知道,也不做什么评断.减少一些重复性的工作,提高开发效率这是最根本的.说白了就是偷懒 ...

  5. yii2 生成随机字符串

    uuid uuid use Faker\Provider\Uuid; Uuid::uuid(); yii自带 生成32位字符串 Yii::$app->getSecurity()->gene ...

  6. Java 中多态的实现(下)

    Java 中多态的另一个语法实现是重写.重载是通过静态分派实现的,重写则是通过动态分派实现的. 在学习动态分派之前,需要对虚拟机的知识有一个初步的了解. 虚拟机运行时数据区 运行 Java 程序时,虚 ...

  7. 查看Sql Server库中某张表的结构

    --快速查看表结构(比较全面的) SELECT CASE WHEN col.colorder = THEN obj.name ELSE '' END AS 表名, col.colorder AS 序号 ...

  8. RHEL/CentOS 7中Nginx的systemd service

    源码安装的nginx ,没有systemd service 管理 nginx 下面教程,告诉你如何设置nginx 的systemd service nginx systemd的服务文件是/usr/li ...

  9. Linux修复日志

    阿里云后台系统报告漏洞,解决记录 中级: RHSA-2019:0049-重要: systemd 安全更新

  10. C#继承是个啥

    继承: 字面意思就是继承 如地主老王有500亩地,老王的儿子小王可以种这五百亩地可以随便拿这五百亩地上面的任何东西 如Controller 你要用从一个controller调用另一个controlle ...