BoilTask

这里写图片描述
这里写图片描述

这里的合法是指
1.所有字符都是由大小写字母、数字、_下划线构成的
2.首字符不能为数字

所以可以轻松写出代码
需要注意的是因为输入有空格 所以不能用 scanf

#include<stdio.h>
#include<string.h>
int main() {
    int T;
    scanf("%d",&T);
    getchar();
    while(T--) {
        char s[55];
        gets(s);
        if(!((s[0]>=\'a\'&&s[0]<=\'z\')||(s[0]>=\'A\'&&s[0]<=\'Z\')||(s[0]==\'_\'))) {
            printf("no\n");
            continue;
        }
        int i;
        for(i=0; i<strlen(s); i++) {
            if(!((s[i]>=\'a\'&&s[i]<=\'z\')||(s[i]>=\'A\'&&s[i]<=\'Z\')||(s[i]==\'_\')||(s[i]>=\'0\'&&s[i]<=\'9\'))) {
                printf("no\n");
                break;
            }
        }
        if(i<strlen(s))
            continue;
        printf("yes\n");
    }
    return 0;
}

题目地址:【杭电】[2024]C语言合法标识符

分类:

技术点:

相关文章:

  • 2021-12-23
  • 2022-01-07
  • 2022-01-19
  • 2021-11-23
  • 2021-07-02
  • 2021-11-20
猜你喜欢
  • 2021-12-17
  • 2022-01-20
  • 2022-02-07
  • 2022-01-29
  • 2022-03-07
  • 2021-12-21
相关资源
相似解决方案