C语言合法标识符

#include <cstdio>
#include <cstring>

int main()
{
	char a[55];
	int n, len;
	scanf("%d", &n);
	getchar();  // 吃掉n后面的回车键
	while(n --)
	{
		gets(a);
		len = strlen(a);
		int length = 0;
		if(a[0] >= '0' && a[0] <= '9')
		{
			printf("no\n");
		}
		else
		{
			for(int i = 0; i < len; ++ i)
			{
				if((a[i] >= '0' && a[i] <= '9') || (a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z') || (a[i] == '_'))
				{
					length ++;
				}
			}
			if(length == len)
			{
				printf("yes\n");
			}
			else
			{
				printf("no\n");
			}
		}
	}
	
	return 0;
} 

  

posted @ 2019-07-30 16:01  青衫客36  阅读(683)  评论(0编辑  收藏  举报