当前位置: 代码迷 >> 综合 >> ZCMU--1516: Name(C语言)
  详细解决方案

ZCMU--1516: Name(C语言)

热度:76   发布时间:2023-12-06 10:10:34.0

题目描述

        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;
}