You are on page 1of 2

1

M1
#include <iostream>
#include <cstring>

using namespace std;

int main() {
char text[501]="", *separatori=" ,.?!;", *p;
cin.getline(text, 501);
int nr_cuv_palindr=0, index=0, final_cuv=0;
while (strchr(separatori, text[index])!=NULL) {
index++;
}
strcpy(text, text+index);
index=strlen(text)-1;
while (strchr(separatori, text[index])!=NULL) {
index--;
}
text[index+1]='\0';
index=0;
while (index<strlen(text)) {
while (strchr(separatori, text[final_cuv])==NULL) {
final_cuv++;
}
final_cuv--;
char temporar[100]="";
int k=0;
for (int contor=index; contor<=final_cuv; contor++) {
temporar[k]=text[contor];
k++;
}
if (strcmp(strrev(temporar), temporar)==NULL) {
nr_cuv_palindr++;
}
index++;
}
cout<<nr_cuv_palindr;
return 0;
}

M2
#include <iostream>
#include <cstring>

using namespace std;

int main() {
char text[501]="", *separatori=" ,.?!;", *p;
cin.getline(text, 501);
int nr_cuv_palindr=0;
p=strtok(text, separatori);
while (p!=NULL) {
char p_sec[100]="";
strcpy(p_sec, p);
if (strcmp(strrev(p_sec), p)==0) {
nr_cuv_palindr++;
}
p=strtok(NULL, separatori);
}
cout<<nr_cuv_palindr;
return 0;
}

2. NU AM STIUT SA FAC

You might also like