Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.7 kB
13
Indexable
Never
#include<bits/stdc++.h>
using namespace std;

vector<string> splitter(string s){
	string z="";
	int i=0;
	vector<string>ans;
	while(i<s.size()){
		if(s[i]==' '){
			if(z!=""){
				ans.push_back(z);
				z="";
			}
		}else{
			z+=s[i];
		}
		i++;
	}
	if(z!=""){
		ans.push_back(z);
		z="";
	}
	return ans;
}

bool isKey(string s){
	unordered_set<string>cp={"begin", "end", "if", "then", "else", "for" , "do" , "while", "switch", "case", "default", "break", "continue", "goto"};
	return cp.count(s);
}
bool isSp(string s){
	unordered_set<string>cp={"!", "@","#", "$","&", "*","_"};
	return cp.count(s);
}
bool isInt(string s){
	int i=0;
	if(s[0]=='+'||s[0]=='-')i++;
	if(i==s.size())return 0;
	while(i<s.size()){
		if(!(s[i]>='0'&&s[i]<='9'))return 0;
    	i++;
	}
	return 1;
}
bool isFloat(string s){
	int i=0;
	if(s[0]=='+'||s[0]=='-')i++;
	if(i==s.size())return 0;
	bool f=0,r=0,p=0,q=0;
	while(i<s.size()){
		if((s[i]>='0'&&s[i]<='9')){
		    if(r==1)p=1;
		    if(f==1)q=1;
		}
		else if(s[i]=='.'&&f==0){
			f=1;
		}else if(s[i]=='e'&&r==0){
			r=1;
			if(i+1<s.size()&&(s[i+1]=='+'||s[i+1]=='-'))i++;
		}
		else return 0;
		i++;
	}
	return (r==p&&(f==q));
}

int main(){
	string s;
	getline(cin,s);
	vector<string>query=splitter(s);
	for(int i=0;i<query.size();i++){
		if(isKey(query[i])){
			cout<<"KEYWORD - "<<query[i]<<"\n";
		}else if(isSp(query[i])){
			cout<<"SPECIAL - "<<query[i]<<"\n";
		}else if(isInt(query[i])){
			cout<<"SIGNED-INTEGER - "<<query[i]<<"\n";
		}else if(isFloat(query[i])){
			cout<<"FLOAT - "<<query[i]<<"\n";
		}else{
			cout<<"UNRECOGNIZED - "<<query[i]<<"\n";
		}
	}
	return 0;
}