#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <cctype>
#include <string>
#include <algorithm>
using namespace std;
set<char> punc = { ';', ':', ',' };
set<char> br = { '(', ')', '{', '}', '[', ']' };
set<string> oper = { "+", "-", "*", "/", ">", ">=", "<", "<=", "==", "!=", "=", "&&", "||", "++", "--", "!" };
set<string> keywords = {"auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "int", "long", "register", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while"};
bool isOp(const string& str) { return oper.find(str) != oper.end(); }
bool isBr(char ch) { return br.find(ch) != br.end(); }
bool isPunc(char ch) { return punc.find(ch) != punc.end(); }
bool isKe(const string& str) { return keywords.find(str) != keywords.end(); }
void proTok(const string& token, map<string, set<string>>& tok) {
if (!token.empty()) {
if (isKe(token))
tok["Keyword"].insert(token);
else if (isdigit(token[0]) || (token[0] == '-' && token.size() > 1 && isdigit(token[1])))
tok["Constant"].insert(token);
else
tok["Identifier"].insert(token);
}
}
void tok(const string& li, map<string, set<string>>& tok) {
string token;
for (size_t i = 0; i < li.size(); ++i) {
char curr = li[i];
if (isspace(curr) || isPunc(curr) || isBr(curr)) {
proTok(token, tok);
token.clear();
if (isPunc(curr))
tok["Punctuation"].insert(string(1, curr));
if (isBr(curr))
tok["Bracket"].insert(string(1, curr));
} else if (i + 1 < li.size() && isOp(string(1, curr) + string(1, li[i + 1]))) {
proTok(token, tok);
token.clear();
tok["Operator"].insert(string(1, curr) + string(1, li[i + 1]));
i++;
} else if (isOp(string(1, curr))) {
proTok(token, tok);
token.clear();
tok["Operator"].insert(string(1, curr));
} else {
token += curr;
}
}
proTok(token, tok);
}
int main() {
map<string, set<string>> tokens; // Renamed from tok to tokens
string li;
cout << "To finish input type 'end'!\n";
while (getline(cin, li)) {
if (li == "end")
break;
tok(li, tokens); // Updated to use the renamed variable
}
for (const auto& kv : tokens) {
cout << kv.first << " <" << kv.second.size() << ">: ";
bool first = true;
for (const auto& token : kv.second) {
cout << (first ? "" : ", ") << token;
first = false;
}
cout << "\n";
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPGNjdHlwZT4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzZXQ8Y2hhcj4gcHVuYyA9IHsgJzsnLCAnOicsICcsJyB9OwoKc2V0PGNoYXI+IGJyID0geyAnKCcsICcpJywgJ3snLCAnfScsICdbJywgJ10nIH07CgpzZXQ8c3RyaW5nPiBvcGVyID0geyAiKyIsICItIiwgIioiLCAiLyIsICI+IiwgIj49IiwgIjwiLCAiPD0iLCAiPT0iLCAiIT0iLCAiPSIsICImJiIsICJ8fCIsICIrKyIsICItLSIsICIhIiB9OwoKc2V0PHN0cmluZz4ga2V5d29yZHMgPSB7ImF1dG8iLCAiYnJlYWsiLCAiY2FzZSIsICJjaGFyIiwgImNvbnN0IiwgImNvbnRpbnVlIiwgImRlZmF1bHQiLCAiZG8iLCAiZG91YmxlIiwgImVsc2UiLCAiZW51bSIsICJleHRlcm4iLCAiZmxvYXQiLCAiZm9yIiwgImdvdG8iLCAiaWYiLCAiaW50IiwgImxvbmciLCAicmVnaXN0ZXIiLCAicmV0dXJuIiwgInNob3J0IiwgInNpZ25lZCIsICJzaXplb2YiLCAic3RhdGljIiwgInN0cnVjdCIsICJzd2l0Y2giLCAidHlwZWRlZiIsICJ1bmlvbiIsICJ1bnNpZ25lZCIsICJ2b2lkIiwgInZvbGF0aWxlIiwgIndoaWxlIn07Cgpib29sIGlzT3AoY29uc3Qgc3RyaW5nJiBzdHIpIHsgcmV0dXJuIG9wZXIuZmluZChzdHIpICE9IG9wZXIuZW5kKCk7IH0K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ICAgICAgICBpZiAoaXNQdW5jKGN1cnIpKQogICAgICAgICAgICAgICAgdG9rWyJQdW5jdHVhdGlvbiJdLmluc2VydChzdHJpbmcoMSwgY3VycikpOwogICAgICAgICAgICBpZiAoaXNCcihjdXJyKSkKICAgICAgICAgICAgICAgIHRva1siQnJhY2tldCJdLmluc2VydChzdHJpbmcoMSwgY3VycikpOwogICAgICAgIH0gZWxzZSBpZiAoaSArIDEgPCBsaS5zaXplKCkgJiYgaXNPcChzdHJpbmcoMSwgY3VycikgKyBzdHJpbmcoMSwgbGlbaSArIDFdKSkpIHsKICAgICAgICAgICAgcHJvVG9rKHRva2VuLCB0b2spOwogICAgICAgICAgICB0b2tlbi5jbGVhcigpOwogICAgICAgICAgICB0b2tbIk9wZXJhdG9yIl0uaW5zZXJ0KHN0cmluZygxLCBjdXJyKSArIHN0cmluZygxLCBsaVtpICsgMV0pKTsKICAgICAgICAgICAgaSsrOwogICAgICAgIH0gZWxzZSBpZiAoaXNPcChzdHJpbmcoMSwgY3VycikpKSB7CiAgICAgICAgICAgIHByb1Rvayh0b2tlbiwgdG9rKTsKICAgICAgICAgICAgdG9rZW4uY2xlYXIoKTsKICAgICAgICAgICAgdG9rWyJPcGVyYXRvciJdLmluc2VydChzdHJpbmcoMSwgY3VycikpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRva2VuICs9IGN1cnI7CiAgICAgICAgfQogICAgfQogICAgcHJvVG9rKHRva2VuLCB0b2spOwp9CgppbnQgbWFpbigpIHsKICAgIG1hcDxzdHJpbmcsIHNldDxzdHJpbmc+PiB0b2tlbnM7ICAvLyBSZW5hbWVkIGZyb20gdG9rIHRvIHRva2VucwogICAgc3RyaW5nIGxpOwoKICAgIGNvdXQgPDwgIlRvIGZpbmlzaCBpbnB1dCB0eXBlICdlbmQnIVxuIjsKCiAgICB3aGlsZSAoZ2V0bGluZShjaW4sIGxpKSkgewogICAgICAgIGlmIChsaSA9PSAiZW5kIikKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgdG9rKGxpLCB0b2tlbnMpOyAgLy8gVXBkYXRlZCB0byB1c2UgdGhlIHJlbmFtZWQgdmFyaWFibGUKICAgIH0KCiAgICBmb3IgKGNvbnN0IGF1dG8mIGt2IDogdG9rZW5zKSB7CiAgICAgICAgY291dCA8PCBrdi5maXJzdCA8PCAiIDwiIDw8IGt2LnNlY29uZC5zaXplKCkgPDwgIj46ICI7CiAgICAgICAgYm9vbCBmaXJzdCA9IHRydWU7CiAgICAgICAgZm9yIChjb25zdCBhdXRvJiB0b2tlbiA6IGt2LnNlY29uZCkgewogICAgICAgICAgICBjb3V0IDw8IChmaXJzdCA/ICIiIDogIiwgIikgPDwgdG9rZW47CiAgICAgICAgICAgIGZpcnN0ID0gZmFsc2U7CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgIlxuIjsKICAgIH0KfQoKCQo=