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 ...
随机推荐
- TCP 协议快被淘汰了,UDP 协议才是新世代的未来?
TCP 协议可以说是今天互联网的基石,作为可靠的传输协议,在今天几乎所有的数据都会通过 TCP 协议传输,然而 TCP 在设计之初没有考虑到现今复杂的网络环境,当你在地铁上或者火车上被断断续续的网络折 ...
- Math Magic ZOJ - 3662
核心是要想到只枚举最小公倍数的因子 因为转移过程中一单添加了不是最小公倍数的因子,那么结果必然不合法,虽然最终答案是对的,但是这样的答案根本用不上,反而时间复杂度大大增加 #include<cs ...
- BZOJ4668 冷战(LCT维护最小生成树)
BZOJ4668 冷战(LCT维护最小生成树) 题面 自己找去 HINT 这道题就是动态加边,然后查询u,v两点最早什么时候联通,强制在线.思考一下,最早什么时候联通不就等同于维护最小生成树吗(把这条 ...
- python3练习100题——004
继续做题-经过python3的测试 原题链接:http://www.runoob.com/python/python-exercise-example4.html 题目:输入某年某月某日,判断这一天是 ...
- 安装oracle11gR2
一.通过百度云等途径下载oracle11gR2 二.安装步骤 1,解压缩文件,将两个压缩文件一起解压. 2,在setup.exe右键--属性--兼容性,勾“以管理员身份运行此程序”. 3,双击“set ...
- 在Visual Studio中将dll以资源的形式嵌入exe中
一.Dll的优点: 1.扩展应用程序的特性 2.简化项目管理 3.有助于节省内存 4.促进资源的共享 5.促进本地化 6.有助于解决平台间的差异 7.可用于特殊目的 有关于dll及注入相关理论资料,可 ...
- Sql注入之注入点类型和是否存在注入判断
SQL注入之判断注入类型注入类型分为数字型和字符型和搜索型例如数字型语句:select * from table where id =3,则字符型如下:select * from table wher ...
- H5手机端开发问题及解决方案
ios竖屏拍照上传,图片被旋转问题 1.通过第三方插件exif-js获取到图片的方向2.new一个FileReader对象,加载读取上传的图片3.在fileReader的onload函数中,得到的图片 ...
- MCPS & MIPS
MIPS:Million Instructions Per Second MCPS:Million Cycles Per Second MIPS = Total Instructions*Sampli ...
- [P4450] 双亲数 - 莫比乌斯反演,整除分块
模板题-- \[\sum\limits_{i=1}^a\sum\limits_{j=1}^b[(i,j)=k] = \sum\limits_{i=1}^a\sum\limits_{j=1}^b[k|i ...