top1编程
← 返回题目
题解

【入门】合法的变量名

1 条题解

  • 0
    @ 2026-7-28 22:44:42
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	string s;
    	bool f;
    	getline(cin,s);
    	for(int i=0;i<s.size();i++){
    		if((isdigit(s[i])||isalpha(s[i])||s[i]=='_')==false){
    			f=false;
    			break;
    		}
    	}
    	if(isdigit(s[0])){
    		f=false;
    	}
    	if(s=="int"||s=="double"||s=="cin"||s=="cout"){
    		f=false;
    	}
    	if(f==false){
    		cout<<"no";
    	}
    	else{
    		cout<<"yes";
    	}
    	return 0;
    }
    
    • 1