C语言合法标识符
Problem Description
输入一个字符串,判断其是否是C的合法标识符。
Input
输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。
Output
对于每组输入数据,输出一行。如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。
Sample Input
3
12ajf
fi8x_a
ff ai_2
Sample Output
no
yes
no
#include#include#includeusing namespace std;
int main(){
int n;
scanf("%d",&n);
//清除输入缓冲区里面的换行符
getchar();
while(n--){
string flag = "no";
char a[50];
gets(a);
string str = a;
//检查第一个字符
if(str[0]=='_'||(str[0]>='A'&&str[0]<='Z')||(str[0]>='a'&&str[0]<='z')){
int con=0;
//检查后面的字符
for(int i=1;i='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z')||(str[i]>='0'&&str[i]<='9'))
con++;
if(con==str.size()-1)
flag = "yes";
}
cout<
查找最大元素
Problem Description
对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串“(max)”。
Input
输入数据包括多个测试实例,每个实例由一行长度不超过100的字符串组成,字符串仅由大小写字母构成。
Output
对于每个测试实例输出一行字符串,输出的结果是插入字符串“(max)”后的结果,如果存在多个最大的字母,就在每一个最大字母后面都插入"(max)"。
Sample Input
abcdefgfedcba
xxxxx
Sample Output
abcdefg(max)fedcba
x(max)x(max)x(max)x(max)x(max)
#include#includeusing namespace std;
int main(){
char b[100];
while(cin>>b){
string str = b;
//记录最大的字符
char ch ='A';
for(int i=0;ich)
ch=str[i];
}
for(int i=0;i
首字母变大写
Problem Description
输入一个英文句子,将每个单词的第一个字母改成大写字母。
Input
输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。
Output
请输出按照要求改写后的英文句子。
Sample Input
i like acm
i want to get an accepted
Sample Output
I Like Acm
I Want To Get An Accepted
#include#include#include#includeusing namespace std;
int main(){
char a[100];
while(gets(a)){
string str = a;
//第一个字符必大写
str[0]=toupper(str[0]);
//空格后的第一个字符必大写
for(int i=1;i