C identifiers

C identifiers

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

题目描述

  Identifiers is an important concept in the C programming language,so it is very necessary for every acmer to be clear about the concept.Identifiers provide names for several language elements,such as functions,variables, labels,etc.

An identifier is a sequence of characters.A valid identifiers 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 character sequences,your task is to judge whether they are valid identifiers.

输入

  The first line of the input contains one integer T ( 0 < T ≤ 100) ,indicating the number of strings in the input.T 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 T lines,output "Yes"(without quote marks) if the character sequence contained in that line make a valid identifier;output "No"(without quote marks)otherwise.

示例输入

7
Valididentifier
ACM_2011
_ACM_SDUT_2011
0_sum
SUM2000--2011
Invalid identifier
Abcde0123_--,;!?"()'::[ACM]

示例输出

Yes
Yes
Yes
No
No
No
No

提示

 

来源

 

示例程序

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值