码迷,mamicode.com
首页 > 其他好文 > 详细

[2011山东省第二届ACM大学生程序设计竞赛]——Identifiers

时间:2014-07-01 13:45:08      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   strong   2014   

Identifiers

Time Limit: 1000MS Memory limit: 65536K

题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2163

题目描写叙述

 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.

演示样例输入

7
ValidIdentifier
valid identifier
valid identifier
0 invalid identifier
1234567
invalid identifier
adefhklmruvwxyz12356790 -.,:;!?‘"()[]ABCDGIJLMQRSTVWXYZ

演示样例输出

Yes
Yes
Yes
No
No
No
No


昊哥最终逃了他的形势与政策课程,过来打辅助了。

上场比赛累的一塌糊涂啊。这次最终释放出来了O(∩_∩)O~,最重要不用翻译英语了,好开心~。~

尽管这次并没有做出来非常多,但慢慢来,会好起来的!


这道题是第一个做出来的,非常水,就是推断输入的字符串是否合法。

简单的来说输入的字符串仅仅能有字母(大写或小写)和下划线,否则都不合法。


#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;
}


[2011山东省第二届ACM大学生程序设计竞赛]——Identifiers,布布扣,bubuko.com

[2011山东省第二届ACM大学生程序设计竞赛]——Identifiers

标签:des   style   blog   http   strong   2014   

原文地址:http://www.cnblogs.com/mfrbuaa/p/3817137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!