当前位置:网站首页>PTA l3-031 thousand hand Guanyin (30 points)
PTA l3-031 thousand hand Guanyin (30 points)
2022-06-21 17:34:00 【WA_ automata】
PTA L3-031 Thousand-hand Bodhisattva (30 branch )

Humans like to use 10 Base number , Probably because humans have two hands 10 A finger is used to count . So in the world of thousand hand Guanyin , The numbers are 10 000 It's binary , Because every Guanyin has 1 000 Both hands ……
Each finger of thousand hand Guanyin corresponds to a symbol ( But the symbols in Guanyin world are too difficult to draw , Let's use a string of lowercase English letters to represent ), It's like humans use their own 10 Root finger correspondence 0 To 9 this 10 A digital . alike , Just like humans put this 10 A number arranged to represent a larger number ,ta They also put these names together to represent larger numbers , And also follow the rules of high on the left and low on the right , Use a dot between adjacent names . Separate , for example pat.pta.cn It means one in the thousand hand Guanyin world 3 digit .
Humans do not know the size of the numbers represented by these symbols . But fortunately , Humans have discovered a string of numbers left by thousand handed Guanyin , And have reason to believe , This string of numbers is ordered from small to large ! So your task came : Please according to this series of orderly numbers , The relative order of symbols represented by each hand of thousand hand Guanyin is deduced .
Be careful : It may not be possible to get the full order from this string of numbers , You just try to get the results you can get . When the relative order between several fingers cannot be determined , Let's arrange them in ascending order according to their English dictionaries . For example, given the following numbers :
pat
cn
lao.cn
lao.oms
pta.lao
pta.pat
cn.pat
We can first infer from the first two numbers pat < cn; According to the order of the high order on the left, we can infer lao < pta < cn; Then, according to the order of the low order when the high order is equal , It can be inferred that cn < oms,lao < pat. To sum up, we get two possible orders :lao < pat < pta < cn < oms; perhaps lao < pta < pat < cn < oms, namely pat and pta The relative order between cannot be determined , At this time, we arrange them in dictionary order , obtain lao < pat < pta < cn < oms.
Input format :
The first line of input gives a positive integer N ( ≤ 1 0 5 ) N (≤10^5) N(≤105), The number of numbers left for thousand hand Guanyin . And then N That's ok , Each line gives a number left by thousand hand Guanyin , No more than 10 digit , The symbol of each bit shall not exceed 3 A lowercase letter indicates , Use... Between two adjacent symbols . Separate .
We assume that the numerical order given is strictly increasing in the world of thousand hand Guanyin . The title guarantee number is 1 0 4 10^4 104 It's binary , That is, the types of symbols must not exceed 1 0 4 10^4 104 Kind of .
Output format :
Output symbols in ascending order in a row . When the relative order between several fingers cannot be determined , In ascending order of their English dictionaries . Between symbols still use . Separate .
sample input :
7
pat
cn
lao.cn
lao.oms
pta.lao
pta.pat
cn.pat
sample output :
lao.pat.pta.cn.oms
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
unordered_map<string,int> d;
unordered_map<string,vector<string>> g;
vector<string> get(string str)
{
vector<string> res;
string word;
for(auto &c:str)
{
if(c=='.')
{
res.push_back(word);
if(!d.count(word)) d[word]=0;
word="";
}
else word+=c;
}
res.push_back(word);
if(!d.count(word)) d[word]=0;
return res;
}
vector<string> topsort()
{
priority_queue<string,vector<string>,greater<string>> Q;
for(auto &[k,v]:d)
if(!v)
Q.push(k);
vector<string> res;
while(!Q.empty())
{
string t=Q.top();Q.pop();
res.push_back(t);
for(auto &p:g[t])
if(--d[p]==0)
Q.push(p);
}
return res;
}
int main()
{
ios::sync_with_stdio(false);
int n;cin>>n;
string str;cin>>str;
vector<string> last=get(str);
for(int i=0;i<n-1;i++)
{
cin>>str;
vector<string> cur=get(str);
if(last.size()==cur.size())
{
for(int j=0;j<(int)cur.size();j++)
if(last[j]!=cur[j])
{
g[last[j]].push_back(cur[j]);
d[cur[j]]++;
break;
}
}
last=cur;
}
vector<string> res=topsort();
cout<<res[0];
for(int i=1;i<(int)res.size();i++)
cout<<"."<<res[i];
return 0;
}
边栏推荐
- [MySQL learning notes 17] sorting out common functions
- Summary of the 16th week
- 软件测试体系学习及构建(13)-测试基础之测试工程师的基本要求
- AttributeError: module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipeline‘
- SCAU软件工程基础
- Vector data download for mainland and global epidemic data, based on geo JSON to SHP
- go corn定时任务简单应用
- xlrd寻找指定内容所在行与行内容
- Integrated base scheme presentation
- BFS与DFS
猜你喜欢
随机推荐
[Error] ‘vector‘ was not declared in this scope
为什么RedisCluster设计成16384个槽?
FragmentStatePagerAdapter 与FragmentPagerAdapter的区别
Niuke.com: large number addition
窗帘做EN 1101易燃性测试过程是怎么样的?
Force deduction solution summary 1108-ip address invalidation
Template: p6114 [template] Lyndon Decomposition & runs (string)
The fundamental task of Natural Science
Kotlin DSL构建
Qt5 knowledge: string list qstringlistmodel
疫情数据对应的大陆和全球的矢量数据下载,基于geojson转shp
今年的 618 不行了?
Comparison of UDP and TCP
算法--按奇偶性交换后的最大数字(Kotlin)
【mysql学习笔记14】DQL语句执行顺序
path. join() 、path. Basename() and path extname()
关于SSM整合,看这一篇就够了~(保姆级手把手教程)
The main relations and differences between Poisson sampling and Bernoulli sampling
QT5知识:字符串列表QStringListModel
compose 编程思想




![[MySQL learning notes 19] multi table query](/img/e6/4cfb8772e14bc82c4fdc9ad313e58a.png)




