题意:

输入两个单词的起始地址和一个正整数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. zabbix监控服务部署脚本

    搭建平台脚本: #!/bin/bash #zabbix监控服务部署 #脚本使用前提:yum搭建,nginx-1.12.2源码包,zabbix-3.4.4源码包,要求源码包尽量在单一目录下,最好在默认管 ...

  2. Yii2框架 常用函数整合

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

  3. C:数组基础

    数组 在程序设计中,为了方便处理数据把具有相同类型的若干变量按有序形式组织起来--称为数组. 数组就是在内存中连续的相同类型的变量空间.同一个数组所有的成员都是相同的数据类型,同时所有的成员在内存中的 ...

  4. springboot项目部署到服务器上

    链接:https://blog.csdn.net/qq_22638399/article/details/81506448#commentsedit 链接2:https://blog.csdn.net ...

  5. Yii2掉index.php?r=

    普通 首先确认apache2配置 1. 开启 apache 的 mod_rewrite 模块 去掉LoadModule rewrite_module modules/mod_rewrite.so前的“ ...

  6. php集成环境、基础标记符

    集成环境:wamp windows apache mysql php lamp linux apache mysql php 标记符: 1.<?php ...... ?> 2.<?p ...

  7. ZOJ 1002 Fire Net(dfs)

    嗯... 题目链接:https://zoj.pintia.cn/problem-sets/91827364500/problems/91827364501 这道题是想出来则是一道很简单的dfs: 将一 ...

  8. 运维数据同步工具:rsync,serync,csync,drbd,info(基于文件系统)

     Rsync官方站点:http://rsync.samba.org 1. Rsync rsync是一款开源的实现数据全量与增量同步备份的工具 生产环境中使用的场景: 1:一般用于数据异地备份 2:用于 ...

  9. window.onresize

    $(function() { window.onresize = function() { alert("abc"); }; window.onresize = function( ...

  10. IMDB-TOP_250-爬虫

    这个小学期Python大作业搞了个获取IMDB TOP 250电影全部信息的爬虫.第二次写爬虫,比在暑假集训时写的熟练多了.欢迎大家评论. ''' ************************** ...