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的更多相关文章

  1. sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)

    题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...

  2. sdut 2159 Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛) 线段树+离散

    先看看上一个题: 题目大意是: 矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条 ...

  3. 2010年山东省第一届ACM大学生程序设计竞赛 Balloons (BFS)

    题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数 ...

  4. Hello World! 2010年山东省第一届ACM大学生程序设计竞赛

    Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...

  5. Phone Number 2010年山东省第一届ACM大学生程序设计竞赛

    Phone Number Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that if a phone number A is anothe ...

  6. angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems ca ...

  7. Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...

  8. 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server

    点击打开链接 2226: Contest Print Server Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 53  Solved: 18 [Su ...

  9. 山东省第四届ACM大学生程序设计竞赛解题报告(部分)

    2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...

随机推荐

  1. Linux安装WebLogic12

    # groupadd weblogic# useradd -g weblogic weblogic# passwd weblogic# mkdir -p /var/bea# chown -R webl ...

  2. Android文字的复制和粘贴

    Android中提供了简单的额复制粘贴功能.代码很简单 复制文字的代码: ClipboardManager cbm= (ClipboardManager) MainActivity.this .get ...

  3. Python字符串格式符号含义

    ====== #字符串格式化符号含义 #%C 格式化字符串及其ASCLL码 >>> '%c' %97 'a' >>> '%c' % 97 'a' >>& ...

  4. Sybase常用函数

    ==================================常用函数===========================================字符串函数1)ISNULL(EXP1, ...

  5. XtraBackup做mysql主从同步

    一.背景: 线上一个主库压力比较大,所以增加一个从库,但是不能重启或者停止主库的正常运行,不能锁库锁表影响业务的正常运行.所以这里想到了XtraBackup 二.XtraBackup介绍: Xtrab ...

  6. Ruby与sass 与compass安装

     Ruby安装 windows平台下使用Rubyinstaller安装 1) 下载Rubyinstaller 2) 安装Rubyinstaller 记得勾选 add ruby executables ...

  7. [亲测有效] - Mac下屏蔽优酷广告最简单的方法

    这里不和圣母婊争论该不该屏蔽广告,仅给出可行方法. Windows下的Adsafe,万能的去广告神器!可惜Mac下没有这款软件,Adblock之流在国内基本是个玩具,但是我们可以通过修改HOST文件达 ...

  8. linux 各种发行版及包管理器的关系

    linux 各种发行版及包管理器的关系 Linux发行版列表 基于Kpkg(Debian 系) Debian GNU / Linux 及其派生发行版使用deb软件包格式,并使用dpkg及其前端作为包管 ...

  9. Android WiFiDirect 学习(二)——Service Discovery

    Service Discovery 简介 在Android WifiDirect学习(一 )中,简单介绍了如何使用WifiDirect进行搜索——连接——传输. 这样会有一个问题,那就是你会搜索到到附 ...

  10. UIButton上图片和文字的位置调整

    UIButton 上默认是图片在左文字在右,而大多数情况这样默认的的显示形式都不能满足我们的需求,接下来我就这个问题分享一下我的心得. 默认情况下,不设置的效果,都是居中实现 UIButton *bu ...