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. Flash-使用变形面板制作花朵

    在Flash中利用"变形"面板的"重置选取和变形"button(在变形面板右下角),能够自己主动将对象进行创造性变形地画图 步骤: (1)先导入一幅图像 (2) ...

  2. 大并发连接的oracle在Linux下内存不足的问题的分析(转)

    最近一台装有Rhel5.3的40G内存的机器上有一个oracle数据库,数据库的SGA设置为20G,当运行业务时,一个业务高峰期时,发现swap频繁交换,CPU 100%,Load很高,基本体现为内存 ...

  3. 2014华为机试西安地区B组试题

    2014华为机试西安地区B组试题 题目一.亮着点灯的盏数 一条长廊里依次装有n(1≤n≤65535)盏电灯,从头到尾编号1.2.3.-n-1.n.每盏电灯由一个拉线开关控制.開始,电灯所有关着. 有n ...

  4. MySQL基金会-基本数据库操作

    1. 删除数据库 DROP DATABASE 数据库名; mysql> drop database test; 即删除数据库模式 2 .创建数据库 create DATABASE 数据库名; m ...

  5. [Django](1093, &quot;You can&#39;t specify target table &#39;fee_details_invoices&#39; for update in FROM clause&quot;) 错误

    dele_id = Fee_details_invoices.objects.filter(fee_detail_id__in=fee_id_list, return_type='2').values ...

  6. (算法入门经典大赛 优先级队列)LA 3135(之前K说明)

    A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor da ...

  7. Cocos2d-x学习笔记(五岁以下儿童) 精灵两种方式播放动画

     这几天在看控件类,临时没有想好实际运用的方向.单纯的创建网上已经有非常多这方面的样例,我就不写了.接下来是学习精灵类.精灵类若是单独学习也是非常easy.于是我加了一些有关动画方面的知识点与精灵 ...

  8. 解决编译时出错提示: 'error: array must be initialized with a brace-enclosed initializer' 的错误

    编译出现这个错误的原因非常简单编译的标准不相同.如果用stdc90,这个就可以直接编译通过了. 下面是代码例子: ...... ] = NULL;或者 :char cmd[256] = '\0'; . ...

  9. Codeforces 9A-Die Roll(意甲冠军)

    A. Die Roll time limit per test 1 second memory limit per test 64 megabytes input standard input out ...

  10. C#(SuperWebSocket)与websocket通信

    原文:C#(SuperWebSocket)与websocket通信 客户端代码 点击可以查看一些关于websocket的介绍 <!DOCTYPE html> <html> &l ...