Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define forn(i, a, n) for(int i = a; i < n; ++i)
- #define pb push_back
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <queue>
- #include <functional>
- #include <map>
- using namespace std;
- #pragma comment(linker, "/STACK:228228000")
- //какая-то пиздец-структура, написанная михаилом
- typedef long long ll;
- struct VK
- {
- map<char, VK> childs;
- ll uses = 0, depth = 0;
- void operator =(ll a)
- {
- depth = a;
- }
- void add(string& str)
- {
- if (str.size() == depth) return;
- char c = str[depth];
- childs[c] = depth + 1;
- childs[c].uses++;
- childs[c].add(str);
- }
- ll check(string& str)
- {
- if (depth == str.size() && childs.size() > 0) return (-10e6);
- char c = str[depth];
- if (str.size() == depth) return (uses == 1);
- return (childs[c].check(str) + (uses == 1));
- }
- };
- bool norm(char c)
- {
- return(c >= 'a' && c <= 'z');
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int c = 0;
- string t, s;
- VK a;
- getline(cin, s);
- while (s.size() != 0)
- {
- t = "";
- int check = 0;
- while (!norm(s[check])) {
- check++;
- c++;
- }
- while (norm(s[check])) {
- t += s[check];
- check++;
- }
- while (check <= s.size()) // условие
- {
- if (check == s.size())
- check++;
- int y = a.check(t);
- if (y < 0)
- c += t.size();
- else
- c += min(t.size() + 2 - a.check(t), (ll)t.size());
- a.add(t);
- t = "";
- while (check < s.size() && !norm(s[check])) {
- check++;
- c++;
- }
- while (check < s.size() && norm(s[check])) {
- t += s[check];
- check++;
- }
- }
- getline(cin, s);
- c++;
- }
- cout << c;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement