You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
/*
小米定义了一种特殊的字符串,规则如下: 1.字符串必须是一个对称字符串,如:aaabbbaaa 2.字符串中第1、2、3个字符一样,第4、5、6个字符一样,依次类推 3.字符串长度为奇数
输入: 3 aaabbbaaa aabbaa aaa
输出: yes no yes */
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool isSymmetric(const char* str){ int n=strlen(str); for(int i=0;i<n/2;++i){ if(str[i]!=str[n-1-i])return false; } return true; } bool isGrouped(const char* str){ int n= strlen(str); for(int i=0;i< n; i += 3){ if(i + 2 >= n)break; if(str[i]!=str[i +1] || str[i]!= str[i + 2])return false; } return true; } bool isValidstring(const char* str){ if(strlen(str)%2==0)return false; if(!isSymmetric(str))return false; if(!isGrouped(str))return false; return true; } int main(){ int n; scanf("%d", &n); char inputs[n][101]; for(int i = 0; i < n; ++i)scanf("%s",inputs[i]); for (int i = 0; i < n; ++i){ if(isValidstring(inputs[i])){ printf("yes\n"); } else { printf("no\n"); } } return 0; }
|