Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iostream>
- #include <fstream>
- #include <cstdio>
- #include <string>
- using namespace std;
- const int MAX = 1e6 + 100;
- bool isletter(char c) {
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
- return true;
- }
- return false;
- }
- struct vertex {
- bool leaf;
- int next[27 * 2 + 10];
- long long count = 0;
- int id = 0;
- };
- vertex bor[MAX + 1];
- int numb;
- char make_char(int n) {
- cerr << "&&&&&&&&" << n << endl;
- if (n < 27) {
- int a = 'A' + n;
- return (char) a;
- } else {
- int a = 'a' - 27 + n;
- cerr << a << endl;
- return (char) a;
- }
- }
- void dfs(int v, string &s) {
- const int alph = 52;
- cerr << "YES" << '\n';
- if (bor[v].leaf) {
- cout << s << ';' << bor[v].count << ';' << bor[v].id << endl;
- }
- for (size_t i = 0; i < alph; ++i) {
- if (bor[v].next[i] != -1 ) {
- char c = make_char(i);
- cout << "********" << c << endl;
- s += c;
- dfs(bor[v].next[i], s);
- }
- }
- }
- void add (string &id, int count, string &country) {
- int v = 0;
- for (size_t i = 0; i < country.size(); ++i) {
- unsigned char c;
- if (isupper(country[i])) {
- c = country[i] - 'A';
- } else {
- c = country[i] - 'a' + 27;
- }
- if (bor[v].next[c] == -1) {
- cout << "fibhseuidwl";
- memset (bor[numb].next, 255, sizeof(bor[numb].next));
- bor[v].next[c] = numb++;
- }
- v = bor[v].next[c];
- }
- bor[v].count += count;
- bor[v].leaf = true;
- int v_term = v;
- bool check_new = false;
- for (size_t i = 0; i < id.size(); ++i) {
- char c = id[i] - '0' + 27 * 2;
- if (bor[v].next[c] == -1) {
- memset (bor[numb].next, 255, sizeof(bor[numb].next));
- bor[v].next[c] = numb++;
- check_new = 1;
- }
- v = bor[v].next[c];
- }
- bor[v].leaf = true;
- if (check_new) {
- bor[v_term].id++;
- }
- }
- int main() {
- //ifstream fin ("input.txt");
- freopen("input.txt", "rt", stdin);
- string s;
- //cin >> s;
- //cout << s;
- while (cin >> s) {
- cout << "nbdjqw";
- string id = "";
- string count = "";
- string country = "";
- size_t ind = 0;
- bool check_format = true;
- for (;ind < s.size(); ++ind) {
- if (isdigit(s[ind])) {
- id += s[ind];
- } else {
- if (s[ind] != ';') {
- check_format = false;
- }
- break;
- }
- }
- ++ind;
- for (;ind < s.size(); ++ind) {
- if (isdigit(s[ind])) {
- count += s[ind];
- } else {
- if (s[ind] != ';') {
- check_format = false;
- }
- break;
- }
- }
- ++ind;
- for (;ind < s.size(); ++ind) {
- if (isletter(s[ind])) {
- country += s[ind];
- } else {
- if (s[ind] != ';') {
- check_format = false;
- }
- break;
- }
- }
- if (!check_format) {
- continue;
- }
- int count1 = stoi(count);
- memset (bor[0].next, 255, sizeof bor[0].next);
- numb = 1;
- add(id, count1, country);
- }
- s = "";
- cout << numb;
- for (int i = 0; i < numb; i++) {
- for (int j = 0; j < 64; j++) {
- cout << bor[i].next[j] << " ";
- }
- cout << '\n';
- }
- dfs(0, s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement