Difficulty: Easy Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example, “A man, a plan, a canal: Panama” is a palindrome. “race a car” is not a palindrome.
language c:
//判断是否是回文,即倒过来和正序是否一样 bool isPalindrome(char* s) { //char a = 'a', A = 'A', zero = '0', nine = '9'; int size = 0; int i; for (i = 0; s[i] != '\0'; i++) { size++; } int front, end; bool ifalphanumeric(char); //for (front = 0, end = size-1 ; front < size && end >= 0;front++, end--) { for (front = 0, end = size-1 ; front < end;front++, end--) { while (!ifalphanumeric(s[front]) && front < end) { front++; } while (!ifalphanumeric(s[end]) && front < end) { end--; } void upper(char *); upper(&s[front]); upper(&s[end]); if (s[front] != s[end]) return false; } return true; } void upper(char *a) { if (*a >= 'a' && *a <= 'z') *a -= 32; return; } bool ifalphanumeric(char a) { if ((a >= 'A' && a <= 'Z') || (a >= 'a' && a <= 'z') || (a >= '0' && a <= '9')) return true; else return false; }