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 ...
随机推荐
- centos 7 安装 Vue
一.安装npmyum install -y npm 二.更新组件yum update openssl 三.安装Vue最新稳定版本npm install vue最新稳定 CSP 兼容版本npm inst ...
- oracle add_month函数
本文转自:https://blog.csdn.net/lanchengxiaoxiao/article/details/7695057 add_months 函数主要是对日期函数进行操作,举例子进行说 ...
- c++ md5算法实现(转)
原文链接:C++计算文件的MD5值 其他:c++输入文件流ifstream用法详解
- laravel本地化扩展包的下载使用
1.下载扩展包 composer require caouecs/laravel-lang:~3.0 2.下载完成之后在根目录下的vendor中caouces\src下就是语言的扩展包 2.1我们复制 ...
- javascript初学笔记
基本语句 赋值条件循环语句 javascript异常处理语句 trycatchfinally语句 Error对象 throw语句 函数 定义 调用 嵌套函数 函数的嵌套定义 内置函数 匿名函数和Fun ...
- MySQL的去重+列的表达式
MySQL的去重+列的表达式 1. 去重 作用:去除SELECT查询出来的结果中重复的数据,重复的数据只显示一条. SELECT * FROM `repeat_num` ...
- Tickets HDU - 1260 简单dp
#include<iostream> using namespace std; const int N=1e5; int T,n; int a[N],b[N]; int dp[N]; in ...
- gazebo仿真踩坑--rviz中设定机器人的目标位置,move_base后台日志报错
启动仿真环境及各种节点(amcl,move_base,map_server)后,在rviz中设定机器人的目标位置,后台日志报错 [ INFO] [1571974242.864525935, 40.51 ...
- jacob导入项目
在 resource 下创建一个 lib 将网上下载的 jacob.jar 放入其中 在 pom 文件中导入相对应的 jar 包 <dependency> <groupId>c ...
- android TextView 支持长按自由复制
因为EditText支持系统的长按自由复制,所以只需要把EditText通过配置达到TextView效果就行了 <EditText android:id="@+id/subject_i ...