大厂笔试题
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.

57 lines
1.2 KiB

  1. /*
  2. :
  3. 1.:aaabbbaaa
  4. 2.123456
  5. 3.
  6. 3
  7. aaabbbaaa
  8. aabbaa
  9. aaa
  10. yes
  11. no
  12. yes
  13. */
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <stdbool.h>
  17. bool isSymmetric(const char* str){
  18. int n=strlen(str);
  19. for(int i=0;i<n/2;++i){
  20. if(str[i]!=str[n-1-i])return false;
  21. }
  22. return true;
  23. }
  24. bool isGrouped(const char* str){
  25. int n= strlen(str);
  26. for(int i=0;i< n; i += 3){
  27. if(i + 2 >= n)break;
  28. if(str[i]!=str[i +1] || str[i]!= str[i + 2])return false;
  29. }
  30. return true;
  31. }
  32. bool isValidstring(const char* str){
  33. if(strlen(str)%2==0)return false;
  34. if(!isSymmetric(str))return false;
  35. if(!isGrouped(str))return false;
  36. return true;
  37. }
  38. int main(){
  39. int n;
  40. scanf("%d", &n);
  41. char inputs[n][101];
  42. for(int i = 0; i < n; ++i)scanf("%s",inputs[i]);
  43. for (int i = 0; i < n; ++i){
  44. if(isValidstring(inputs[i])){
  45. printf("yes\n");
  46. }
  47. else {
  48. printf("no\n");
  49. }
  50. }
  51. return 0;
  52. }