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.

演示样例输入

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

演示样例输出

Yes
Yes
Yes
No
No
No
No

提示

 

来源

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

解题思路:

推断是否输入的字符串为合法标识符。

代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
using namespace std;
string str[1000];
int main()
{
int n;cin>>n;
getchar();//必须得加这个,吸收空格,否则后面用getline会出错
for(int i=1;i<=n;i++)
{
getline(cin,str[i]);
bool ok=1;
int len=str[i].length();
if(!isalpha(str[i][0])&&str[i][0]!='_')//首字母不是字母也不是下划线
{
cout<<"No"<<endl;
continue;
}
for(int j=0;j<len;j++)
{
if(!isdigit(str[i][j])&&!isalpha(str[i][j])&&str[i][j]!='_')//不符合要求
{
ok=0;
break;
}
}
if(ok)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

[2011山东ACM省赛] Identifiers(模拟)的更多相关文章

  1. [2011山东ACM省赛] Mathman Bank(模拟题)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/sr19930829/article/details/24187925 Mathman Bank ni ...

  2. [2011山东ACM省赛] Sequence (动态规划)

    Sequence Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Given an integer number sequence ...

  3. [2011山东ACM省赛] Binomial Coeffcients(求组合数)

    Binomial Coeffcients nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...

  4. [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)

    Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which on ...

  5. [2012山东ACM省赛] Pick apples (贪心,全然背包,枚举)

    Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描写叙述 Once ago, there is a mystery yard which ...

  6. 山东ACM省赛历届入口

    山东省第一届ACM大学生程序设计竞赛 山东省第二届ACM大学生程序设计竞赛 山东省第三届ACM大学生程序设计竞赛 山东省第四届ACM大学生程序设计竞赛 山东省第五届ACM大学生程序设计竞赛 山东省第六 ...

  7. [2013山东ACM]省赛 The number of steps (可能DP,数学期望)

    The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...

  8. hdu 4036 2011成都赛区网络赛F 模拟 **

    为了确保能到达终点,我们需要满足下面两个条件 1.能够到达所有山顶 2.能够在遇到苦土豆时速度大于他 二者的速度可以用能量守恒定律做,苦土豆的坐标可通过三角形相似性来做 #include<cst ...

  9. 第八届山东ACM省赛F题-quadratic equation

    这个题困扰了我长达1年多,终于在今天下午用两个小时理清楚啦 要注意的有以下几点: 1.a=b=c=0时 因为x有无穷种答案,所以不对 2.注意精度问题 3.b^2-4ac<0时也算对 Probl ...

随机推荐

  1. Android中目的地Intent的使用

    一.什么是Intent? Intent的中文意思是目的.在Android中也是“目的”的意思.就是我们要去哪里,从这个activity要前往另一个Activity就需要用到Intent. 示例代码一: ...

  2. 黄聪:Microsoft Enterprise Library 5.0 系列教程(一) : Caching Application Block (初级)

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(一) : Caching Application Block (初级) 本篇文章具体官方解释请参照以下链接: h ...

  3. 整理QTP知识之1

    以下说明由网络其他文章整合而成. 一.关于QTP的说明 QTP是目前市场上占有率最高的一款自动化测试工具,也是每一位测试工作者最想掌握的工具之一,也是目前流行的基于GUI的功能自动化测试工具之一. Q ...

  4. CC2530 外部中断 提醒

    #include "ioCC2530.h" #define uchar unsigned char #define led1    P1_0 #define led2    P1_ ...

  5. mysql多实例的配置(转)

    1.创建多实例的目录: mkdir -p /data/mysql/mysql_3307/{data,tmp,logs} mkdir -p /data/mysql/mysql_3308/{data,tm ...

  6. 询url包括字符串参数(js高度注意事项)

    以防万一  url="http://write.blog.csdn.net/postedit? id=5&search=ok" function getArgs() { v ...

  7. Apache Curator获得真正的

    Apache Curator获得真正的 Curator它是Netflix一家公司来源Zookeeper顾客,与Zookeeper相比于提供本地客户端,Curator的抽象层次更高,简化了Zookeep ...

  8. 【Android 应用程序开发】 Fragment 详细说明

    笔者 : 汉书亮 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/38064191 本博客代码地址 : -- 单一 Fragmen ...

  9. 怎么确定你的CPU是否支持64位虚拟化

    http://www.grc.com/securable.htm 第一个64位表示你的电脑最多支持多少位的系统,32或者64. 第二个表示你的硬件是否支持DEP?Yes,支持.No,不支持.OFF,表 ...

  10. xp硬盘安装Fedora14 过程记录及心得体会(fedora14 live版本680M 和fedora14 DVD版本3.2G的选择)

    这次电脑奔溃了,奇怪的是直接ghost覆盖c盘竟然不中.之前电脑上硬盘安装的fedora14操作系统,也是双系统.不知道是不是这个问题,记得同学说过,在硬盘装fedora之后,要手动修改c盘隐藏的那个 ...