Palindrom – siruri de caractere C++

Se verifica daca un cuvant citit de la tastatura este sau nu palindrom. Exemple de cuvinte de tip palindrom : ‘abcdcba’, ‘ana’,’1881′.

Observatie: Functia tolower converteste o litera mare in litera mica. Exemplu : tolower(‘A’) = ‘a’; tolower(‘a’) = ‘a’;

Exemplu:

Spor la lucru! Daca aveti intrebari nu ezitati sa le lasati in comentarii, va vom raspunde cat de repede putem 🙂

5 Comments

  1. #include
    #include
    using namespace std;

    int main(){

    char a[201],c[201],aux[201];

    cin.get(a,200);
    strcpy(aux,a);
    strrev(a);

    strcpy(c,a);
    if(strcmp(aux,c)==0)
    cout<<"palindrom";

    }

    7

    Reply

  2. unsigned int palindrom (char s[100])

    {unsigned int i, j, k;

    i=0; j=strlen(s)-1; k=0′

    while(i<j) { if(s==s[j]) k=k+1;

    i=i+1; j=j-1;}

    if (k==(strlen(s)-1)/2) return 1 SAU cout<<"PALINDROM" SAU return k;

    else return 0 SAU cout<<"NU ESTE PALINDROM";

    Reply

    1. Salut. Rezolvarea ta nu tine cont de diacritice si este, de asemenea case-sensitive. In rest e ok. Succes si spor la lucru.

      Reply

  3. #include
    #include
    using namespace std;
    int main(){
    char a[100],b[100], aux[100];
    int ok=0;
    cout<>a;
    cout<>b;
    strcpy(aux,strrev(b));
    for(int i=0; i<strlen(a);i++){
    for(int j=0; j<strlen(aux);j++){
    if(a[i]!=aux[j]){
    ok++;
    }
    }
    }
    if(ok==0){cout<<"este";
    } else cout<<"nu este";
    }
    de ce nu functioneaza???????????

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *