杭电100题c语言,杭电OJ100题——2024-2026(C++版)

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值