-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopology.cpp
71 lines (57 loc) · 1.15 KB
/
topology.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// topology.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<set>
using namespace std;
string word_order(vector<string>& words) {
if (words.size() == 0) return "invalid";
char first = words[0][0];
set<char> character;
unordered_map<char, int> indegree;
unordered_map<char, multiset<char>> hash;
unordered_map<char, char> nextt;
for (auto word : words) {
for (auto ch : word)
indegree[ch] = 0;
}
for (int i = 1; i < words.size(); i++)
{
int k = 0,
len1 = words[i - 1].size(),
len2 = words[i].size();
for (size_t l = 0; l < len2; l++)
{
character.insert(words[i][l]);
}
while (k < min(len1, len2))
{
if (words[i - 1][k] != words[i][k])
{
if (nextt.count(words[i-1][k])==0)
{
nextt[words[i - 1][k]] == words[i][k];
}
break;
}
}
}
string str;
return str;
}
int main() {
vector<string> words;
string str;
while (cin >> str) {
words.push_back(str);
char ch = getchar();
if (ch == '\n') break;
}
string res = word_order(words);
cout << res << endl;
return 0;
}