#include <iostream>
#include <string.h>
using namespace std;
#define MAX 300
int myStrcmp(char s1[], char s2[]);
int myStrlen(char s[], int k);
void myStrcpy(char s[], int vt, char s1[], int k);
void mySubstr(char s[], int b, int count, char ss[]);
bool myStrcat(char s1[], char s2[]);
void StringReverse(char st[]);
int main()
{
char s[MAX];
fgets(s,300,stdin);
if (myStrcmp(s, "") == 0)
cout << "Chuoi rong." << endl;
else
{
StringReverse(s);
cout << s << endl;
}
return 0;
}
int myStrlen1(char s[]) {
int length = 0;
while (s[length] != '\0') {
++length;
}
return length;
}
int myStrcmp(char s1[], char s2[]) {
int m = myStrlen1(s1);
int n = myStrlen1(s2);
for (int i = 0; i < min(m, n); ++i) {
if (s1[i] > s2[i]) {
return 1;
}
else if (s1[i] < s2[i]) {
return -1;
}
}
if (m > n) return 1;
else if(m < n) return -1;
else return 0;
}
void myStrcpy1(char s[], char s1[]) {
int i = 0;
while (s1[i] != '\0') {
s[i] = s1[i];
++i;
}
s[i] = '\0';
}
void myStrcat1(char s1[], char s2[]) {
int i = 0;
while (s1[i] != '\0') {
++i;
}
int j = 0;
while (s2[j] != '\0') {
s1[i] = s2[j];
++i;
++j;
}
s1[i] = '\0';
}
void StringReverse(char s[]) {
s[myStrlen1(s) - 1] = '\0'; // Bỏ ký tự xuống dòng cuối cùng
if (myStrcmp(s, "") == 0) {
cout << "Chuoi rong." << endl;
return;
}
char a[100][100];
int n = 0;
char* token = strtok(s, " ");
while (token != NULL) {
myStrcpy1(a[n], token);
++n;
token = strtok(NULL, " ");
}
for (int i = 0; i < n; ++i) {
int len = myStrlen1(a[i]);
for (int j = 0; j < len / 2; ++j) {
char temp = a[i][j];
a[i][j] = a[i][len - j - 1];
a[i][len - j - 1] = temp;
}
}
myStrcpy1(s, a[0]);
for (int i = 1; i < n; ++i) {
myStrcat1(s, " ");
myStrcat1(s, a[i]);
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgTUFYIDMwMAoKaW50IG15U3RyY21wKGNoYXIgczFbXSwgY2hhciBzMltdKTsKaW50IG15U3RybGVuKGNoYXIgc1tdLCBpbnQgayk7CnZvaWQgbXlTdHJjcHkoY2hhciBzW10sIGludCB2dCwgY2hhciBzMVtdLCBpbnQgayk7CnZvaWQgbXlTdWJzdHIoY2hhciBzW10sIGludCBiLCBpbnQgY291bnQsIGNoYXIgc3NbXSk7CmJvb2wgbXlTdHJjYXQoY2hhciBzMVtdLCBjaGFyIHMyW10pOwp2b2lkIFN0cmluZ1JldmVyc2UoY2hhciBzdFtdKTsKCmludCBtYWluKCkKewoJY2hhciBzW01BWF07CglmZ2V0cyhzLDMwMCxzdGRpbik7CglpZiAobXlTdHJjbXAocywgIiIpID09IDApCgkJY291dCA8PCAiQ2h1b2kgcm9uZy4iIDw8IGVuZGw7CgllbHNlCgl7CgkJU3RyaW5nUmV2ZXJzZShzKTsKCQljb3V0IDw8IHMgPDwgZW5kbDsKCX0KCXJldHVybiAwOwp9CmludCBteVN0cmxlbjEoY2hhciBzW10pIHsKICAgIGludCBsZW5ndGggPSAwOwogICAgd2hpbGUgKHNbbGVuZ3RoXSAhPSAnXDAnKSB7CiAgICAgICAgKytsZW5ndGg7CiAgICB9CiAgICByZXR1cm4gbGVuZ3RoOwp9CgppbnQgbXlTdHJjbXAoY2hhciBzMVtdLCBjaGFyIHMyW10pIHsKICAgIGludCBtID0gbXlTdHJsZW4xKHMxKTsKICAgIGludCBuID0gbXlTdHJsZW4xKHMyKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbWluKG0sIG4pOyArK2kpIHsKICAgICAgICBpZiAoczFbaV0gPiBzMltpXSkgewogICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAoczFbaV0gPCBzMltpXSkgewogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgfQogICAgaWYgKG0gPiBuKSByZXR1cm4gMTsKICAgIGVsc2UgaWYobSA8IG4pIHJldHVybiAtMTsKICAgIGVsc2UgcmV0dXJuIDA7Cn0KCnZvaWQgbXlTdHJjcHkxKGNoYXIgc1tdLCBjaGFyIHMxW10pIHsKICAgIGludCBpID0gMDsKICAgIHdoaWxlIChzMVtpXSAhPSAnXDAnKSB7CiAgICAgICAgc1tpXSA9IHMxW2ldOwogICAgICAgICsraTsKICAgIH0KICAgIHNbaV0gPSAnXDAnOwp9Cgp2b2lkIG15U3RyY2F0MShjaGFyIHMxW10sIGNoYXIgczJbXSkgewogICAgaW50IGkgPSAwOwogICAgd2hpbGUgKHMxW2ldICE9ICdcMCcpIHsKICAgICAgICArK2k7CiAgICB9CiAgICBpbnQgaiA9IDA7CiAgICB3aGlsZSAoczJbal0gIT0gJ1wwJykgewogICAgICAgIHMxW2ldID0gczJbal07CiAgICAgICAgKytpOwogICAgICAgICsrajsKICAgIH0KICAgIHMxW2ldID0gJ1wwJzsKfQoKdm9pZCBTdHJpbmdSZXZlcnNlKGNoYXIgc1tdKSB7CiAgICBzW215U3RybGVuMShzKSAtIDFdID0gJ1wwJzsgLy8gQuG7jyBrw70gdOG7sSB4deG7kW5nIGTDsm5nIGN14buRaSBjw7luZwogICAgaWYgKG15U3RyY21wKHMsICIiKSA9PSAwKSB7CiAgICAgICAgY291dCA8PCAiQ2h1b2kgcm9uZy4iIDw8IGVuZGw7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgY2hhciBhWzEwMF1bMTAwXTsKICAgIGludCBuID0gMDsKICAgIGNoYXIqIHRva2VuID0gc3RydG9rKHMsICIgIik7CiAgICB3aGlsZSAodG9rZW4gIT0gTlVMTCkgewogICAgICAgIG15U3RyY3B5MShhW25dLCB0b2tlbik7CiAgICAgICAgKytuOwogICAgICAgIHRva2VuID0gc3RydG9rKE5VTEwsICIgIik7CiAgICB9CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgIGludCBsZW4gPSBteVN0cmxlbjEoYVtpXSk7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBsZW4gLyAyOyArK2opIHsKICAgICAgICAgICAgY2hhciB0ZW1wID0gYVtpXVtqXTsKICAgICAgICAgICAgYVtpXVtqXSA9IGFbaV1bbGVuIC0gaiAtIDFdOwogICAgICAgICAgICBhW2ldW2xlbiAtIGogLSAxXSA9IHRlbXA7CiAgICAgICAgfQogICAgfQogICAgbXlTdHJjcHkxKHMsIGFbMF0pOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBuOyArK2kpIHsKICAgICAgICBteVN0cmNhdDEocywgIiAiKTsKICAgICAgICBteVN0cmNhdDEocywgYVtpXSk7CiAgICB9Cn0=