Untitled
unknown
c_cpp
a year ago
1.3 kB
5
Indexable
#include <iostream>
#include <regex>
#include <string>
#include <cctype>
using namespace std;
bool check_camelCase(string x){
int len = x.length();
if(len > 10){
return false;
}
char y[len];
strcpy(y, x.c_str());
int count = 0;
for(int i = 0; i < len; i++){
if(isupper(y[i])){
count++;
}
}
if(count == 1){
return true;
}
else{
return false;
}
return true;
}
bool check_Number(string x){
int len = x.length();
if(len > 10){
return false;
}
char y[len];
strcpy(y, x.c_str());
for(int i = 0; i < len; i++){
if((i!=0 && isdigit(y[i])) || (i!=len-1 && isdigit(y[i]))){
return false;
}
}
return true;
}
bool check_Keywords(string x){
string keywords[] = {"int", "cin", "cout", "float" , "endl", "strcpy", "return" , "false" , "true" , "void", "bool"};
int len1 = sizeof(keywords)/sizeof(keywords[0]);
for(int i = 0 ; i < len1 ; i++){
if(x == keywords[i]){
return 0;
}
}
return 1;
}
int main(){
string x;
cout<<"Enter a variable: ";
cin >> x;
cout << (check_camelCase(x)&&check_Number(x)&&check_Keywords(x)) << endl;
}
//rules:
/*
1) camelcasing only
2) max length 10
3) can't have integer in between them
4) must not start with caps
*/Editor is loading...
Leave a Comment