#include <iostream>
#include <cstring>
using namespace std;
// Functie pentru a verifica daca un caracter este litera
bool esteLitera(char c) {
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}
// Functie pentru a numara caracterele alfabetice dintr-un cuvant
int nrChar(const char* cuvant) {
int count = 0;
for (int i = 0; cuvant[i] != '\0'; i++) {
if (esteLitera(cuvant[i])) {
count++;
}
}
return count;
}
void inter(char c[], char rez[]) {
int n = strlen(c);
int litere = nrChar(c);
strcpy(rez, c);
int mijloc = litere / 2;
int leftIndex = 0, rightIndex = 0;
for (int i = 0; i < n; ++i) {
if (esteLitera(c[i])) {
if (leftIndex < mijloc) {
rez[mijloc + rightIndex] = c[i];
rightIndex++;
} else {
rez[leftIndex - mijloc] = c[i];
leftIndex++;
}
}
}
if (litere % 2 != 0) {
rez[mijloc] = c[mijloc];
}
}
int main() {
char car[1000], rezCuv[1000];
cout << "Introduceti textul (se opreste cu linie goala):" << endl;
while (cin.getline(car, 1000) && strlen(car) > 0) {
char* cuvant = strtok(car, " ");
while (cuvant != nullptr) {
inter(cuvant, rezCuv); // Procesam fiecare cuvant
cout << rezCuv << " ";
cuvant = strtok(nullptr, " ");
}
cout << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAovLyBGdW5jdGllIHBlbnRydSBhIHZlcmlmaWNhIGRhY2EgdW4gY2FyYWN0ZXIgZXN0ZSBsaXRlcmEKYm9vbCBlc3RlTGl0ZXJhKGNoYXIgYykgewogICAgcmV0dXJuIChjID49ICdBJyAmJiBjIDw9ICdaJykgfHwgKGMgPj0gJ2EnICYmIGMgPD0gJ3onKTsKfQogCi8vIEZ1bmN0aWUgcGVudHJ1IGEgbnVtYXJhIGNhcmFjdGVyZWxlIGFsZmFiZXRpY2UgZGludHItdW4gY3V2YW50CmludCBuckNoYXIoY29uc3QgY2hhciogY3V2YW50KSB7CiAgICBpbnQgY291bnQgPSAwOwogICAgZm9yIChpbnQgaSA9IDA7IGN1dmFudFtpXSAhPSAnXDAnOyBpKyspIHsKICAgICAgICBpZiAoZXN0ZUxpdGVyYShjdXZhbnRbaV0pKSB7CiAgICAgICAgICAgIGNvdW50Kys7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIGNvdW50Owp9Cgp2b2lkIGludGVyKGNoYXIgY1tdLCBjaGFyIHJleltdKSB7CiAgICBpbnQgbiA9IHN0cmxlbihjKTsKICAgIGludCBsaXRlcmUgPSBuckNoYXIoYyk7CiAgICBzdHJjcHkocmV6LCBjKTsKICAgIGludCBtaWpsb2MgPSBsaXRlcmUgLyAyOwogICAgaW50IGxlZnRJbmRleCA9IDAsIHJpZ2h0SW5kZXggPSAwOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICBpZiAoZXN0ZUxpdGVyYShjW2ldKSkgewogICAgICAgICAgICBpZiAobGVmdEluZGV4IDwgbWlqbG9jKSB7CiAgICAgICAgICAgICAgICByZXpbbWlqbG9jICsgcmlnaHRJbmRleF0gPSBjW2ldOwogICAgICAgICAgICAgICAgcmlnaHRJbmRleCsrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmV6W2xlZnRJbmRleCAtIG1pamxvY10gPSBjW2ldOwogICAgICAgICAgICAgICAgbGVmdEluZGV4Kys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBpZiAobGl0ZXJlICUgMiAhPSAwKSB7CiAgICAgICAgcmV6W21pamxvY10gPSBjW21pamxvY107CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgY2hhciBjYXJbMTAwMF0sIHJlekN1dlsxMDAwXTsKICAgIGNvdXQgPDwgIkludHJvZHVjZXRpIHRleHR1bCAoc2Ugb3ByZXN0ZSBjdSBsaW5pZSBnb2FsYSk6IiA8PCBlbmRsOwoKICAgIHdoaWxlIChjaW4uZ2V0bGluZShjYXIsIDEwMDApICYmIHN0cmxlbihjYXIpID4gMCkgewogICAgICAgIGNoYXIqIGN1dmFudCA9IHN0cnRvayhjYXIsICIgIik7CiAgICAgICAgd2hpbGUgKGN1dmFudCAhPSBudWxscHRyKSB7CiAgICAgICAgICAgIGludGVyKGN1dmFudCwgcmV6Q3V2KTsgIC8vIFByb2Nlc2FtIGZpZWNhcmUgY3V2YW50CiAgICAgICAgICAgIGNvdXQgPDwgcmV6Q3V2IDw8ICIgIjsKICAgICAgICAgICAgY3V2YW50ID0gc3RydG9rKG51bGxwdHIsICIgIik7CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9