Advertisement
Tankado95

Prima le palindrome [Ricontrollare]

Jun 4th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAX 41
  5.  
  6.  
  7. int ispalindroma(char *array){
  8. int i=0,j=0,palindroma=0;
  9. int dim=strlen(array);
  10. j=dim-1;
  11.             while(i<dim/2 && palindroma==0){
  12.                 if (array[i]!=array[j])
  13.                     palindroma=1;
  14.                
  15.                 j--;
  16.                 i++;
  17.                                
  18.             }
  19.    
  20. return palindroma;
  21. }
  22.  
  23.  
  24. int main(){
  25. int n=0,i=0,j=0,ris=0;
  26.     scanf("%d",&n);
  27.  
  28. char ** array=(char**)malloc(sizeof(char*)*n);
  29.    
  30.    
  31.     for (i=0;i<n;i++){
  32.         array[i]=(char*)malloc(sizeof(char)*MAX);
  33.         scanf("%s", array[i]);
  34.         }
  35.    
  36.  
  37.     for(i=0;i<n;i++){
  38.         ris=ispalindroma(array[i]);
  39.         if (ris==0)
  40.             printf("%s\n",array[i]);
  41.            
  42.         }
  43.     for(i=0;i<n;i++){
  44.         ris=ispalindroma(array[i]);
  45.         if (ris==1)
  46.             printf("%s\n",array[i]);
  47.         }
  48.                
  49.  
  50.  
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement