日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[2011山东ACM省赛] Identifiers(模拟)

發布時間:2024/1/17 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [2011山东ACM省赛] Identifiers(模拟) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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;elsecout<<"No"<<endl;}return 0; }


?

版權聲明:本文博客原創文章,博客,未經同意,不得轉載。






本文轉自mfrbuaa博客園博客,原文鏈接:http://www.cnblogs.com/mfrbuaa/p/4686198.html,如需轉載請自行聯系原作者


總結

以上是生活随笔為你收集整理的[2011山东ACM省赛] Identifiers(模拟)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。