sdut 2163:Identifiers(第二届山东省省赛原题,水题)
2014-04-21 18:41
405 查看
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> using namespace std; int main() { int i,j,n; cin>>n; getchar(); for(i=1;i<=n;i++){ char a[110]; cin.getline(a,110,'\n'); if(('a'<=a[0] && a[0]<='z') || ('A'<=a[0] && a[0]<='Z') || a[0]=='_'){ for(j=0;a[j];j++) if(!(('a'<=a[j] && a[j]<='z') || ('A'<=a[j] && a[j]<='Z') || ('0'<=a[j] && a[j]<='9') || a[j]=='_') ) break; if(a[j]) cout<<"No"<<endl; else cout<<"Yes"<<endl; } else cout<<"No"<<endl; } return 0; } /************************************** Problem id : SDUT OJ 2163 User name : Miracle Result : Accepted Take Memory : 452K Take Time : 0MS Submit Time : 2014-04-20 09:18:49 **************************************/
Freecode : www.cnblogs.com/yym2013
相关文章推荐
- SDUT 2163 Identifiers 山东省第二届ACM大学生程序设计竞赛
- 山东省第二届ACM省赛 Identifiers
- sdut2165 Crack Mathmen (山东省第二届ACM省赛)
- Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)
- Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)
- Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)
- sdut2165 Crack Mathmen (山东省第二届ACM省赛)
- Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)
- Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)
- Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)
- sdut 2161 Simple Game(山东省第二届acm省赛A题)(博弈论Nim+Bush?)
- 山东省第一届ACM省赛 E SDUT 2155 Emergency(最短路)
- Binomial Coeffcients 山东省第二届ACM省赛 G题
- 山东省第二届ACM省赛 Mathmen
- 山东省第一届ACM省赛 F SDUT 2156 Fairy tale
- [2011山东省第二届ACM大学生程序设计竞赛]——Identifiers
- 山东省第一届ACM省赛 G SDUT 2157 Greatest Number(暴力枚举)
- 山东省第二届ACM省赛 Binomial Coeffcients(组合数学)
- SDUT 3895 (山东省第八届ACM省赛C题) fireworks 杨辉三角+乘法逆元
- 山东省第一届ACM省赛 H SDUT 2158 Hello World!(穷举)