• 【STL】【HDU2024】C语言合法标识符【水题】


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

    既然要求了全体同学都要刷完杭电100题,那我还是以身作则,也都给刷完吧~~~

    这些水题真的是都快刷吐了   不知道刷过多少道了  就当做查缺补漏吧

    不过还真的发现了一个有意思的题目,用普通的办法判断真的是太麻烦了,真是一个体力活

    还没注意过这几个库函数  用起来才发现这么简洁

    getline();

    getline()函数使用详解

    头文件 C++<cctype> (C语言使用<ctype.h>)

    isalpha

    int isalpha( int ch )  

    功能:判断字符ch是否为英文字母

    说明:若ch为英文字母,返回非0(小写字母为2,大写字母为1)。若不是字母,返回0。

    isalnum

    int isalnum(int c);

    功能:判断字符变量c是否为字母或数字
    说明:当c为数字0-9或字母a-z及A-Z时,返回非零值,否则返回零。

    代码:

     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
    ");
    63         else
    64             printf("no
    ");
    65 
    66     }
    67     
    68     return 0;
    69 }
    文章搬运自我的个人博客http://duny31030.top 原博客为静态博客,因备份丢失无法继续更新,所以又搬运回博客园,可能部分文章阅读体验不好,可以到我的静态博客搜索相同标题查看
  • 相关阅读:
    css-css背景
    css-概述和选择器
    html-补充
    html-示例代码
    html-表格和列表
    html-表单
    html-常用标签
    html- 头部元素
    html-介绍
    SQLAlchemy-对象关系教程ORM-连接,子查询
  • 原文地址:https://www.cnblogs.com/duny31030/p/8946874.html
Copyright © 2020-2023  润新知