1 solutions

  • 0
    @ 2025-3-3 16:32:50

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
    	string s;
    	//读入字符串 
    	getline(cin,s);
    	bool r = true;
    	
    	int i;
    	//循环看有没有字母、数字、下划线以外的字符
    	for(i = 0;i < s.size();i++){
    		//含有非法字符 
    		if((isalpha(s[i]) || isdigit(s[i]) || s[i] == '_') == false){
    			r = false;
    			break;
    		}
    	} 
    	
    	//判断不能以数字开头
    	if(isdigit(s[0])){
    		r = false;
    	} 
    	
    	//判断不是四个特殊含义的单词
    	if(s == "int" || s == "double" || s == "cout" || s == "cin") {
    		r = false;
    	}
    	
    	if(r == true){
    		cout<<"yes"<<endl;
    	}else{
    		cout<<"no"<<endl;
    	} 
    	
    	
        return 0;
    }
    
    
    • 1

    Information

    ID
    10404
    Time
    1000ms
    Memory
    16MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By