From a3dd2581ed4847670f81157091016c14ca18803d Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Tue, 14 Jan 2020 18:29:11 +0700 Subject: [usth/MATH2.3] Mathemate Discretely --- usth/MATH2.3/5/grammar-to-automata.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 usth/MATH2.3/5/grammar-to-automata.cc (limited to 'usth/MATH2.3/5/grammar-to-automata.cc') diff --git a/usth/MATH2.3/5/grammar-to-automata.cc b/usth/MATH2.3/5/grammar-to-automata.cc new file mode 100644 index 0000000..125b3c9 --- /dev/null +++ b/usth/MATH2.3/5/grammar-to-automata.cc @@ -0,0 +1,29 @@ +#include +#include +#include + +using namespace std; + +int +main () +{ + int n; + cin >> n; + + unordered_map> automata; + unordered_map finals; + for (int i = 0; i < n; ++i) + { + char c; + string s, t; + cin >> c >> t >> s; + if (s == "$") + finals[c] = 1; + else + automata[c][s[0] - '0'] = (s.length () == 1) ? '$' : s[1]; + } + + cout << automata.size () << endl; + for (auto& [c, m] : automata) + cout << c << '\t' << m[0] << '\t' << m[1] << '\t' << finals[c] << endl; +} -- cgit 1.4.1