题意:

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

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string a1,a2;
int n;
string s,nex;
char x;
map<string,string>mp;
map<string,int>m;
int main(){
cin>>a1>>a2>>n;
for(int i=;i<=n;++i){
cin>>s>>x>>nex;
mp[s]=nex;
}
int cnt=;
while(++cnt){
if(cnt&&&a1.size()==){
++m[a1];
if(m[a1]==){
cout<<a1;
return ;
}
a1=mp[a1];
}
else if(!(cnt&)&&a2.size()==){
++m[a2];
if(m[a2]==){
cout<<a2;
return ;
}
a2=mp[a2];
}
if(a1.size()==&&a2.size()==){//不要使用a1.size()==a2.size()==2,尽管有些许样例可能如愿输出,实际上和想要的效果相差甚远,这样写先将a1的size和a2的size比较,相等即为1,不相等即为0,永远不会等于2
cout<<-;
break;
}
}
return ;
}

【PAT甲级】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. 1032 Sharing (25分)

    1032 Sharing (25分) 题目 思路 定义map存储所有的<地址1,地址2> 第一set存放单词1的所有地址(通过查找map) 通过单词二的首地址,结合map,然后在set中查 ...

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

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

  5. PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)

    1078 Hashing (25 分)   The task of this problem is simple: insert a sequence of distinct positive int ...

  6. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

    1070 Mooncake (25 分)   Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...

  7. PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*

    1029 Median (25 分)   Given an increasing sequence S of N integers, the median is the number at the m ...

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

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

  9. PAT 甲级 1032 Sharing

    https://pintia.cn/problem-sets/994805342720868352/problems/994805460652113920 To store English words ...

随机推荐

  1. UIAutomation反编译调试一句话体验

    ILSpy比dotpeek好使 ILSpy生成的pdb调试起来基本没发现问题,最多只是代码步骤位置和实际位置差了一行而已,不影响判断. dotpeek反编译出来的代码能看,但调试是基本没办法定位的,位 ...

  2. C语言进行csv文件数据的读取

    C语言进行csv文件数据的读取: #include <stdio.h> #include <string.h> #include <malloc.h> #inclu ...

  3. Yii2框架 常用函数整合

    1.使用事务添加数据: public function create() { if($this->validate()) { $trans = Yii::$app->db->begi ...

  4. AT24C02芯片学习记录

    1.首先看AT24C02芯片的引脚说明 2.芯片的型号与存储容量(bit)的对应关系: 3.总线时序 我对时序的理解: 时钟线分两种:一种是外部时钟源控制时钟线低电平持续多久高电平持续多久,就像串口: ...

  5. opencv:图像的算术操作

    前提:输入图像的大小和类型必须一致 越界处理: 大于255,则会减去255 小于0,则等于0 基本计算,加减乘除 #include <opencv2/opencv.hpp> #includ ...

  6. 基于Tesseract实现图片文字识别

    一.简介  Tesseract是一个开源的文本识别[OCR]引擎,可通过Apache 2.0许可获得.它可以直接使用,或者使用API从图像中提取打印的文本,支持多种语言.该软件包包含一个ORC引擎[l ...

  7. h5页面判断移动端系统为Android或IOS

    最近遇到了一个需求,即所谓的 app+web 混合开发,需要将 h5 内嵌到 APP 中,这个时候因为要对 Android 和 IOS 有不同的处理逻辑,所以我们就需要判断一下,移动端的系统到时是哪一 ...

  8. WARNING: bridge-nf-call-iptables is disabled解决

    执行docker info出现如下警告 WARNING: bridge-nf-call-iptables is disabledWARNING: bridge-nf-call-ip6tables is ...

  9. Docker for YApi--一键部署YApi

    获取YApi镜像$ docker pull mrjin/yapi:latest 注意:本仓库目前只支持安装,暂不支持升级,请知晓.如需升级请备份mongoDB内的数据. docker-compose ...

  10. BUG搬运工:CSCun88303-CIMC Memory Leak : Can't SSH/HTTP to CIMC

    Symptom:Unable to SSH/HTTP to the CIMC of the C-series server, however the CIMC can be pinged. Also ...