山东省第二届ACM大学生程序设计竞赛:Identifiers
来源:互联网 发布:那年呐服饰淘宝代理可信吗 编辑:程序博客网 时间:2024/04/30 14:00
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.
示例输入
7ValidIdentifiervalid_identifiervalid_identifier0 invalid identifier1234567invalid identifieradefhklmruvwxyz12356790 -.,:;!?'"()[]ABCDGIJLMQRSTVWXYZ
示例输出
YesYesYesNoNoNoNo
提示
来源
山东省第二届ACM大学生程序设计竞赛
#include <iostream>#include <cstring>#include <string>#include <stdio.h>using namespace std;int judge1(char a){ if((a>=97&&a<=122)||(a>=65&&a<=90)||(a=='_')) return 1; return 0;}int judge2(char a){ if((a>=97&&a<=122)||(a>=65&&a<=90)||(a=='_')||(a>=48&&a<=57)) return 1; return 0;}int main(){ int n; cin>>n; char b; cin>>b; while(n--) { char a[200]; gets(a); if(judge1(a[0])) { int i=1,j=0; while(a[i]!='\0') { if(judge2(a[i])) { j++; } i++; } if(j==i-1) { cout<<"Yes"<<endl; } else cout<<"No"<<endl; } else { cout<<"No"<<endl; } } return 0;}
0 0
- 山东省第二届ACM大学生程序设计竞赛——Identifiers
- 山东省第二届ACM大学生程序设计竞赛:Identifiers
- SDUT 2163 Identifiers 山东省第二届ACM大学生程序设计竞赛
- 山东省第二届ACM大学生程序设计竞赛 Identifiers
- [2011山东省第二届ACM大学生程序设计竞赛]——Identifiers
- Identifiers(第二届ACM大学生程序设计竞赛 )
- Sequence(山东省第二届ACM大学生程序设计竞赛)
- 山东省第二届ACM大学生程序设计竞赛:Binomial Coeffcients
- 山东省第二届ACM大学生程序设计竞赛 Sequence
- 山东省第七届ACM大学生程序设计竞赛
- 第四届 山东省ACM大学生程序设计竞赛
- 第七届 山东省ACM大学生程序设计竞赛
- 山东省第二届ACM大学生程序设计竞赛 The Android University ACM Team Selection Contest
- 山东省第二届ACM大学生程序设计竞赛:The Android University ACM Team Selection Contest
- [2011山东省第二届ACM大学生程序设计竞赛]——Mathman Bank
- 山东省第二届ACM大学生程序设计竞赛(原题) D:Binomial Coeffcients
- 组队周赛_山东省第二届ACM大学生程序设计竞赛
- [2011山东省第二届ACM大学生程序设计竞赛]——Crack Mathmen
- 一滴水推醒了英雄的春天
- 愿时光待你温暖如初
- 相反数
- php中json数据接口创建及调用
- 错误 1 error C2440: “=”: 无法从“const char [11]”转换为“LPCWSTR”
- 山东省第二届ACM大学生程序设计竞赛:Identifiers
- 機器學習基石(Machine Learning Foundations) 机器学习基石 作业三 课后习题解答
- PHP中的语言结构详解
- 3——Building Microservices: Inter-Process Communication in a Microservices Architecture
- 折线图的绘制
- C++ STL中Map的按Key排序和按Value排序
- 配置集群各机器间免密码登陆(开启ssh互信)
- 菜单
- codeforces 660B. Seating On Bus