0% found this document useful (0 votes)
9 views1 page

Palindrome Word

The document contains a C++ program that checks if a given string is a palindrome based on the frequency of its characters. It counts the occurrences of each character and determines if the string meets the conditions for being a palindrome. The output indicates whether the input string is a palindrome or not.

Uploaded by

bouziani.hwau
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Palindrome Word

The document contains a C++ program that checks if a given string is a palindrome based on the frequency of its characters. It counts the occurrences of each character and determines if the string meets the conditions for being a palindrome. The output indicates whether the input string is a palindrome or not.

Uploaded by

bouziani.hwau
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

/******************************************************************************

Input: string with length = n (1,1E6)

AAAACACBA
Output
AACABACAA

*******************************************************************************/
#include <bits/stdc++.h>

//typedef long long ll;

int main()
{
std::string word;
std::cin >> word;
int len = word.length();
char lettre='A';
int freq[26]={0};
while (lettre!='Z')
{
for (int i=0; i<len; i++)
{
if (word[i]==lettre) // AAAACACBA
{
freq[int(word[i])-65]++;
}
}
lettre++;
}
int freqPair=0, freqImpair=0;
for (int i=0; i<26; i++)
{
if (freq[i]%2==0)
freqPair++;
else
freqImpair++;
}
bool condition1, condition2;
condition1 = len%2==0 && freqPair!=0 && freqImpair==0;
condition2 = len%2==1 && freqImpair!=0;
if (condition1)
std::cout << word << " est palindrome\n";
else
std::cout << word << " est non palindrome\n";
return 0;
}

You might also like