【PAT甲级】1032 Sharing (25 分)
题意:
输入两个单词的起始地址和一个正整数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 分)的更多相关文章
- PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)
1032 Sharing (25 分) To store English words, one method is to use linked lists and store a word let ...
- 1032 Sharing (25分)
1032 Sharing (25分) 题目 思路 定义map存储所有的<地址1,地址2> 第一set存放单词1的所有地址(通过查找map) 通过单词二的首地址,结合map,然后在set中查 ...
- 【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 ...
- PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)
1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive int ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
- 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
https://pintia.cn/problem-sets/994805342720868352/problems/994805460652113920 To store English words ...
随机推荐
- [AST Babel Plugin] Transform code, add line:column number for console log
For example we have current code: function add(a, b) { console.log(a, b) return a + b } function sub ...
- PHP 基础 自动类型转换之比较运算符
<?php var_dump(' 123fg456'>=122); var_dump('some string' == 0); var_dump(123.0 == '123d456'); ...
- Qt: 释放窗口资源
1. 对于使用指针,使用new创建的窗口,当然可以使用delete显示的释放其占用的资源: Widget *w = new Widget(); delete w; 2. 对于使用指针,使用new创 ...
- 安卓开发:打印Log
在iOS开发中使用NSLog进行打印调试,在安卓中使用的是Log.v(tag, msg);等进行打印调试. 参考:[https://blog.csdn.net/salary/article/detai ...
- python3 利用VideoCapture模块读取多个相机名称
模块pip安装地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#videocapture
- IIS-简介
参考:https://www.jb51.net/article/85909.htm IIS是什么 iis是用来做什么的? IIS全程为Internet Information Service(In ...
- Ansible自动化搭建及工具集和常见模块、命令详情(重点)
一.ansible介绍 1.ansible简介 官方的title是“Ansible is Simple IT Automation”——简单的自动化IT工具. Ansible跟其他IT自动化技术的区别 ...
- C语言:找出一个大于给定整数m且紧随m的素数,-求出能整除x且不是偶数的数的个数,
//函数fun功能:找出一个大于给定整数m且紧随m的素数,并作为函数值返回. #include <stdlib.h> #include <conio.h> #include & ...
- ASP.NET Core搭建多层网站架构【5-网站数据库实体设计及映射配置】
2020/01/29, ASP.NET Core 3.1, VS2019, EntityFrameworkCore 3.1.1, Microsoft.Extensions.Logging.Consol ...
- 吴裕雄--天生自然Numpy库学习笔记:NumPy 副本和视图
副本是一个数据的完整的拷贝,如果我们对副本进行修改,它不会影响到原始数据,物理内存不在同一位置. 视图是数据的一个别称或引用,通过该别称或引用亦便可访问.操作原有数据,但原有数据不会产生拷贝.如果我们 ...