The solution is to determine whether there are any odd characters in the string. If the number of such characters is greater than 1, it means that it cannot form a background; if it is less than or equal to 1, it can form a background.
Strlen () is used, and put into the for loop can easily lead to lower program running efficiency. For example, when the input string is large, it is 10 ^ 5 characters long.
For (INT I = 0; I <strlen (string); I ++) causes the program to run slowly. Switch:
Int length = strlen (string); For (INT I = 0; I <length; I ++) can greatly improve efficiency.
#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>void findPalind(char *arr){ int flag = 0; // Find the required answer here. Print Yes or No at the end of this function depending on your inspection of the string int result[26]; for (int i=0; i<26; i++) { result[i] = 0; } int lenth = (int)strlen(arr); for (int i=0; i<lenth; i++) { int index = (int)*(arr + i) - (int)‘a‘; if (result[index] == 0) { result[index] = 1; } else { result[index] = 0; } } int sum = 0; for (int i=0; i<26; i++) { sum += result[i]; } if (sum >= 2) { flag = 1; } else { flag = 0; } if (flag==0) printf("YES\n"); else printf("NO\n"); return;}int main() { char arr[100001]; scanf("%s",arr); findPalind(arr); return 0;}Code