#include "stdafx.h" #include <iostream> #include <string> #include <cctype> using namespace std; int main () { string s1,s2; string::iterator it; getline(cin,s1); for (it=s1.begin();it<s1.end();it++) { if (*it>='A' && *it<='Z') *it+=32; if (isalpha(*it)) s2+=*it; } s1.clear(); string::reverse_iterator rit; for (rit=s2.rbegin();rit<s2.rend();rit++) s1+=*rit; if (s1.compare(s2)==0) cout<<"Palindrom"; else cout<<"Nu este palindrom"; system("pause"); return 0; } Cod C++. Acest cod poate fi simplificat prin utilizarea functiilor implicite (de exemplu: reverse() din <algorithm>). ______________________________________________ #include "stdafx.h" #include <iostream> #include <string> #include <cctype> using namespace std; int main () { string s1,s2; string::iterator it; getline(cin,s1); for (it=s1.begin();it<s1.end();it++) { if (*it>='A' && *it<='Z') *it+=32; if (isalpha(*it)) s2+=*it; } s1.clear(); string::reverse_iterator rit; for (it=s2.begin(),rit=s2.rbegin();it<s2.end(),rit<s2.rend();it++,rit++) if (*it!=*rit) { cout<<"Nu este palindrom"; system("pause"); return 0; } cout<<"Palindrom"; system("pause"); return 0; } C++ Problema rezolvata fara inversarea string-ului. ______________________________________________ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> char x[1001],y[1001]; int main () { int i,j,n; gets(x); n=strlen(x); j=0; for (i=0;i<n;i++) { if (isalpha(x[i]) && x[i]<='Z' && x[i]>='A') x[i]+=32; if (isalpha(x[i])) { y[j]=x[i]; j++; } x[i]='\0'; } n=strlen(y); for (i=0,j=n-1;i<n,j>=0;i++,j--) if (y[i]!=y[j]) { printf("Nu este palindrom"); system("pause"); return 0; } printf("Palindrom"); system("pause"); return 0; } Rezolvare C.