标签:des style blog http strong 2014
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.
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,布布扣,bubuko.com
[2011山东省第二届ACM大学生程序设计竞赛]——Identifiers
标签:des style blog http strong 2014
原文地址:http://www.cnblogs.com/mfrbuaa/p/3817137.html