Identifiers Time Limit: 1000 ms memory limit: 65536 K Question: http://acm.sdut.edu.cn/sdutoj/problem.php? Action = showproblem & problemid = 2163 description identifier is an important concept in the C programming language. Identifiers provide names for several language elements, such as functions, variables, labels, etc.
An identifier is a sequence of characters. A valid identifier can contain only upper and lower case alphabetic characters, underscore and digits, and must begin with an alphabetic character or an underscore. given a list of chararcter sequences, write a program to check if they are valid identifiers.
Enter the first line of the input contains one integer, N, indicating the number of strings in the input. n lines follow, each of which contains at least one and no more than 100 characters. (Only upper and lower case alphabetic characters, digits, underscore (""), hyphen ("-"), period (". "), comma (", "), colon (": "), semicolon ("; "), exclamation mark ("! "), Question mark ("? "), Single and double quotation marks, Parentheses, white space and square brackets may appear in the character sequences.) Output
For each of the N lines, output "yes" (without quote marks) if the character sequence contained in that line make a valid identifier; output "no" (without quote marks) otherwise.
Demo Input
7ValidIdentifiervalid identifiervalid identifier0 invalid identifier1234567invalid identifieradefhklmruvwxyz12356790 -.,:;!?‘"()[]ABCDGIJLMQRSTVWXYZ
Demo output
YesYesYesNoNoNoNo
HaogeFinally, he escaped his situation and policy courses and came to assist him.
The game was a mess. This time, O (∩ _ ∩) O ~ was finally released ~, The most important thing is that you do not need to translate english ~.~
Although this time has not been done a lot, it will be better soon!
This is the first question. It is very difficult to infer whether the input string is legal.
Simply put, the input string can only contain letters (uppercase or lowercase) and underscores (_). Otherwise, the input string is invalid.
#include <iostream>#include <string>#include <stdio.h>#include <string.h>using namespace std;bool judge_zm(char c){ if((c>=‘a‘ && c<=‘z‘) || (c>=‘A‘ && c<=‘Z‘) || c==‘_‘) return true; return false;}int main(){ bool flag; int i,n,len; char str[101]; cin>>n; cin.getline(str,101,‘\n‘); while(n--) { cin.getline(str,101,‘\n‘); len=strlen(str); flag=0; for(i=0;i<len;++i) { if(!judge_zm(str[i])) { flag=1; break; } } if(flag) cout<<"No"<<endl; else cout<<"Yes"<<endl; } return 0;}