You are on page 1of 2

#include <iostream>

#include<fstream>
#include<vector>
#include <unordered_map>

class Palindrom
{
private:
std::vector<char>vectorChar;
std:: unordered_map<char, int> umap;
int impar;
char imparChar;

public:
void Citire()
{
char currentValue;
std::ifstream file("p3.txt");

while (file >> currentValue)


{

vectorChar.push_back(currentValue);

file.close();
for (char& i : vectorChar)
std::cout << i;
std::cout << std::endl;

bool isOdd(const int x)


{
return (x % 2) != 0;
}

std:: string getPalindrome()


{
impar = 0;
for (char& i : vectorChar)

umap[i]++;

for (auto x : umap) {


if (isOdd(x.second)) {
impar++;
imparChar = x.first;
}
}

if (impar > 1 || impar == 1 && vectorChar.size() % 2 == 0)

return " ";


std:: string firstHalf = "", secondHalf = "";
for (auto x : umap) {

std:: string s(x.second / 2, x.first);

firstHalf = firstHalf + s;
secondHalf = s + secondHalf;
}

return (impar == 1)
? (firstHalf + imparChar + secondHalf)
: (firstHalf + secondHalf);
}

};

int main()
{
Palindrom s;
s.Citire();
std::cout<<s.getPalindrome();

return 0;
}

You might also like