ZCMU--1516: Name(C语言)

题目描述

        There was a boy called ZDD, and he loved a girl whose name is SZD. They loved each other deeply. After saving SZD from TIANKENG, they led a happy life. And later they had a son, and choosing name of their son was a big problem. ZDD was very like “ABB” style. For example, “ZhaoDongDong” is a “ABB” style name, and “ChenLiJian” is not. Then ZDD wanted to know if a name was “ABB” style or not?

Note that A and B should be different!

输入

The first line is an integer T, which indicates the number of test case.

For each test case, there is a string S, which indicates the name of their son. The length of the string is not more than 100. The first letter of every word will be capital.Besides, the name string only contains uppercase and lowercase letters.

输出

        For each test case, if the name is “ABB” style output “Yes”, otherwise output “No” in one line.

样例输入

4
ZhaoDongDong
ChenLiJian
XuXuXu
ZhaoLi

样例输出

Yes
No
No
No
解析:题目就是让我判断名字是否为ABB型,是输出Yes,不是输出No.
个人思路是另外开三个数组来存姓和名,例如ChenLiJian,Chen存在数组aLi存在数组bJian存在数组c中,然后最后利用strcmp函数来判断是否满足ABB型就OK
#include <stdio.h>
#include <string.h>
char k[30],a[10],b[10],c[10];//K数组为原始姓名字符串 
int h[5];//用来标记大写字母位置,用来把姓名拆分成3部分 
int main()
{
	int n,i,m,s,l;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(s=0;s<10;s++) a[s]='\0',b[s]='\0',c[s]='\0';//多组,初始化 
		scanf("%s",k);
		m=0;
		for(s=1;s<strlen(k);s++){
			if(k[s]>='A'&&k[s]<='Z') h[m]=s,m++; //确定大写字母位置,开头字母一定为大写,我们就从第二位开始 
		}
		for(s=0;s<h[0];s++) a[s]=k[s];  //姓 
		l=0;
		for(s=h[0];s<h[1];s++) b[l]=k[s],l++;   //名1 
		l=0;
		for(s=h[1];s<strlen(k);s++) c[l]=k[s],l++;  //名2 
		if(strcmp(a,b)!=0&&strcmp(a,c)!=0&&strcmp(b,c)==0){ //判断 
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值