Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // T06-15.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- using namespace std;
- const int ALPHABET_SIZE = 28;
- struct Trie
- {
- struct Trie* children;
- bool visited;
- long long value;
- };
- int index(char c)
- {
- if (c == '-')
- {
- return 26;
- }
- if (c == '.')
- {
- return 27;
- }
- return c - 'a';
- }
- int main(void)
- {
- int n;
- scanf("%d", &n);
- struct Trie* root = NULL;
- struct Trie* currentNode;
- for (int i = 0; i < n; i++)
- {
- char s[101];
- scanf("%s", s);
- int string_length = strlen(s);
- currentNode = root;
- for (int j = 0; j < string_length; j++)
- {
- cout << "IF " << s[j] << endl;
- if (currentNode == NULL)
- {
- currentNode->children = (struct Trie*)malloc(ALPHABET_SIZE * sizeof(struct Trie));
- currentNode = currentNode->children + index(s[j]);
- cout << "YES " << s[j] << endl;
- currentNode->value = -1;
- }
- else
- {
- cout << "What?" << endl;
- }
- }
- long long current_value;
- scanf("%lld", ¤t_value);
- currentNode->value = current_value;
- }
- int m;
- scanf("%d", &m);
- for (int i = 0; i < m; i++)
- {
- bool p = false;
- char s[101];
- scanf("%s", s);
- int n = strlen(s);
- currentNode = root;
- for (int j = 0; j < n; j++)
- {
- currentNode = currentNode->children + index(s[j]);
- if (currentNode == NULL)
- {
- p = true;
- break;
- }
- }
- if (p)
- {
- printf("-1\n");
- continue;
- }
- printf("%lld\n", currentNode->value);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement