Identifiers

来源:互联网 发布:淘宝清洗后钱该怎么办 编辑:程序博客网 时间:2024/06/06 01:56

Identifiers

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

 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.

输入

 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.)

输出

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.

示例输入

7ValidIdentifiervalid_identifiervalid_identifier0 invalid identifier1234567invalid identifieradefhklmruvwxyz12356790 -.,:;!?'"()[]ABCDGIJLMQRSTVWXYZ

示例输出

YesYesYesNoNoNoNo

提示

 

来源

山东省第二届ACM大学生程序设计竞赛

示例程序

 
#include<stdio.h>  #include<string.h>  char a[1000];  int main()  {  int i,j,n,m,k,t;  scanf("%d",&n);  getchar();  for(i=0;i<n;i++)  {  gets(a);  m=strlen(a);  k=0;  for(j=0;j<m;j++)  {  if(j==0)  {  if((a[0]>='a'&&a[0]<='z')||(a[0]>='A'&&a[0]<='Z')||a[0]=='_')  continue;  else  {  k=1;  break;  }  }  else  {  if((a[j]>='a'&&a[j]<='z')||(a[j]>='A'&&a[j]<='Z')||(a[j]<='9'&&a[j])>='0'||a[j]=='_')  continue;  else  {  k=1;  break;  }  }  }  //printf("%s\n",a);  if(k==1)  printf("No\n");  else  printf("Yes\n");  }  } 

0 0
原创粉丝点击