Advertisement
VF-

Untitled

VF-
Nov 18th, 2022 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. int palindroma_e(char str[]);
  6.  
  7. int main() {
  8.     // szoveg bekerese, fuggvenyhivas, eredmeny kiirasa
  9.  
  10.     char sor[50];
  11.  
  12.     printf("Sor: ");
  13.     fgets(sor, sizeof(sor), stdin);  
  14.  
  15.     printf("Ez %spalindrom\n", palindroma_e(sor) ? "" : "nem ");
  16. }
  17.  
  18. int palindroma_e(char str[]) {
  19.     // annak megallapitasa, hogy a parameterkent kapott szoveg palindrom-e
  20.  
  21.     int bal = -1, jobb = strlen(str);
  22.  
  23.     while (bal < jobb) {
  24.         do {
  25.             bal++;
  26.         } while (bal < jobb && str[bal] == ' ');
  27.         do {
  28.             jobb--;
  29.         } while (bal < jobb && str[jobb] == ' ');
  30.  
  31.         if (bal < jobb && tolower(str[bal]) != tolower(str[jobb])) {
  32.             return 0;
  33.         }
  34.     }
  35.  
  36.     return 1;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement