[2011 Shandong second ACM College Student Program Design Competition] -- identifiers

Source: Internet
Author: User
Identifiers Time Limit: 1000 ms memory limit: 65536 K Question: http://acm.sdut.edu.cn/sdutoj/problem.php? Action = showproblem & problemid = 2163 description 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.

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

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.

Demo Input
7ValidIdentifiervalid identifiervalid identifier0 invalid identifier1234567invalid identifieradefhklmruvwxyz12356790 -.,:;!?‘"()[]ABCDGIJLMQRSTVWXYZ
Demo output
YesYesYesNoNoNoNo


HaogeFinally, he escaped his situation and policy courses and came to assist him.

The game was a mess. This time, O (∩ _ ∩) O ~ was finally released ~, The most important thing is that you do not need to translate english ~.~

Although this time has not been done a lot, it will be better soon!


This is the first question. It is very difficult to infer whether the input string is legal.

Simply put, the input string can only contain letters (uppercase or lowercase) and underscores (_). Otherwise, the input string is invalid.


#include <iostream>#include <string>#include <stdio.h>#include <string.h>using namespace std;bool judge_zm(char c){    if((c>=‘a‘ && c<=‘z‘) || (c>=‘A‘ && c<=‘Z‘) || c==‘_‘)    return true;    return false;}int main(){    bool flag;    int i,n,len;    char str[101];    cin>>n;    cin.getline(str,101,‘\n‘);    while(n--)    {        cin.getline(str,101,‘\n‘);        len=strlen(str);        flag=0;        for(i=0;i<len;++i)        {            if(!judge_zm(str[i]))            {                flag=1;                break;            }        }        if(flag)    cout<<"No"<<endl;        else    cout<<"Yes"<<endl;    }    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.