1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string categorySearch(string s) {
vector<string> keyword { "if","else","then"};
vector<string> identifier { "tom","jerry" };
vector<int> digit { 0,1,2,3,4,5,6,7,8,9 };
vector<string> special { "(",")","[","]","+","-","=" };
vector<string> character { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z" };
string category = "unknown";
if (find(keyword.begin(), keyword.end(), s) != keyword.end()) {
category = "keyword";
}
else if (find(identifier.begin(), identifier.end(), s) != identifier.end()) {
category = "identifier";
}
else if (find(digit.begin(), digit.end(), s) != digit.end()) {
category = "digit";
}
else if (find(special.begin(), special.end(), s) != special.end()) {
category = "special";
}
else if(find(character.begin(), character.end(), s) != character.end()) {
category = "character";
}
return category;
}
| |