1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <iostream>
#include<conio.h>
using namespace std;
char* miroir(char*w);
int equal(char*u,char*v);
int palindrome(char*w);
int longueur(char*str);
main()
{
char mot[255];
cout <<"entrer votre mot : ";
gets(mot);
if(palindrome(mot)==1) cout <<mot<<" est un palindrome ";
if(palindrome(mot)==0) cout <<mot<<" n'est pas un palindrome ";
cout <<"\n\n\n ---- fin du programme -----\n\n";
getch();
}
char* miroir(char*w)
{
int i,ii;
char str[255];
for(i=0;i<longueur(w);i++)
{
str[i]=w[longueur(w)-1-i];
ii=i;
}
str[ii+1]='\0'; //pr ne pas ecrire des symboles à la fin du mot!!!
return str;
}
int equal(char*u,char*v)
{
int i,ii,a;
for(i=0;u[i]!='\0';i++)
{
if(u[i]==v[i])
{
a=1;
ii=i;
continue;
}
else
{
a=0;
break;
}
}
if(a==0) return 0;
if(a==1)
{
if(v[ii+1]=='\0') return 1;
else return 0;
}
}
int palindrome(char*w)
{
if(equal(w,miroir(w))==1) return 1;
if(equal(w,miroir(w))==0) return 0;
}
int longueur(char*str)
{
int i,j=0;
for(i=0;str[i]!='\0';i++)
{
j++;
}
return j;
} |