【STL】【HDU2024】C Language Legal Identifier【Water Question】

Link: http://acm.hdu.edu.cn/showproblem.php?pid=2024

Since all the students are required to finish the 100 questions of Hangdian, then I should lead by example and finish them all~~~

These water questions are really about to vomit. I don't know how many questions have been brushed, so I think it's a check for gaps and leaks.

However, I really found an interesting topic. It is really too troublesome to judge by ordinary methods. It is really a manual job.

I haven't noticed these library functions before I found it so concise

 

 

getline();

Detailed explanation of the use of the getline() function

 

 

Header file C++<cctype> (C language uses <ctype.h>)

isalpha

int isalpha( int ch )  

Function: Determine whether the character ch is an English letter

Description: If ch is an English letter, return non-0 (lowercase letter is 2, uppercase letter is 1). Returns 0 if it is not a letter.

isalnum

int isalnum(int c);

Function: Determine whether the character variable c is a letter or a number
Description: When c is the number 0-9 or the letters az and AZ, it returns a non-zero value, otherwise it returns zero.

 

 

Code:

 1 // 实在懒得改了  下次再说吧
 2 #define _CRT_SBCURE_NO_DEPRECATE
 3 #include <set>
 4 #include <map>
 5 #include <cmath>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #include <string>
10 #include <cstdio>
11 #include <cstdlib>
12 #include <cstring>
13 #include <iostream>
14 #include <algorithm>
15 #include <functional>
16 #include <cctype>
17 
18 using namespace std;
19 
20 #define ll long long
21 #define max3(a,b,c) fmax(a,fmax(b,c))
22 #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
23 
24 const int maxn = 110;
25 const int INF = 0x3f3f3f3f;
26 
27 bool cmp(const int &a,const int &b)
28 {
29     return a>b;
30 }
31 
32 
33 int main()
34 {
35     int n;
36     scanf("%d",&n);
37     getchar();
38     while(n--)
39     {    
40         string s;
41         getline(cin,s);
42         // cout << s << endl;
43         int flag = 1;
44         if(isalpha(s[0])  || s[0] == '_')
45         {
46             for(int i = 0;i < s.size();i++)
47             {
48                 if(isalnum(s[i]) == 0 && s[i] != '_')
49                 {
50                     flag = 0;
51                     // cout << "22" << endl;
52                     // continue;
53                     break;
54                 }
55             }
56         }
57         else
58         {
59             flag = 0;
60         }
61         if(flag)
62             printf("yes\n");
63         else
64             printf("no\n");
65 
66     }
67     
68     return 0;
69 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324851142&siteId=291194637