#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 myStrlen(char s[], int k)
{
k = 0;
while(s[k] != '\0' && s[k] != '\n')
k++;
return k;
}
int myStrcmp(char s1[], char s2[])
{
if(s1[0] == '\n' || s1[0] == '\0')
return 0;
return 1;
}
void StringReverse(char st[])
{
int len = myStrlen(st, len), temp;
bool check = true;
for(int i = 0; i < len; i++)
if(st[i] == ' ')
{
check = false;
break;
}
if(check)
{
for(int i = 0; i < len; i++)
cout << st[i];
st[0] = '\0';
return;
}
for(temp = len - 1; temp >= 0; temp--)
{
if(st[temp] == ' ')
break;
}
for(int i = temp + 1; i < len; i++)
cout << st[i];
cout << ' ';
for(int i = temp; i >= 0; i--)
if(st[i] == ' ')
for(int j = i - 1; j >= 0; j--)
if(st[j] == ' ')
{
for(int k = j + 1; k < i; k++)
{
cout << st[k];
}
i = j;
cout << ' ';
}
temp = 0;
while(st[temp] != ' ')
cout << st[temp++];
st[0] = '\0';
return;
}
CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIE1BWCAzMDAKCmludCBteVN0cmNtcChjaGFyIHMxW10sIGNoYXIgczJbXSk7CmludCBteVN0cmxlbihjaGFyIHNbXSwgaW50IGspOwp2b2lkIG15U3RyY3B5KGNoYXIgc1tdLCBpbnQgdnQsIGNoYXIgczFbXSwgaW50IGspOwp2b2lkIG15U3Vic3RyKGNoYXIgc1tdLCBpbnQgYiwgaW50IGNvdW50LCBjaGFyIHNzW10pOwpib29sIG15U3RyY2F0KGNoYXIgczFbXSwgY2hhciBzMltdKTsKdm9pZCBTdHJpbmdSZXZlcnNlKGNoYXIgc3RbXSk7CgppbnQgbWFpbigpCnsKCWNoYXIgc1tNQVhdOwoJZmdldHMocywzMDAsc3RkaW4pOwoJaWYgKG15U3RyY21wKHMsICIiKSA9PSAwKQoJCWNvdXQgPDwgIkNodW9pIHJvbmcuIiA8PCBlbmRsOwoJZWxzZQoJewoJCVN0cmluZ1JldmVyc2Uocyk7CgkJY291dCA8PCBzIDw8IGVuZGw7Cgl9CglyZXR1cm4gMDsKfQoKaW50IG15U3RybGVuKGNoYXIgc1tdLCBpbnQgaykKewogICAgayA9IDA7CiAgICB3aGlsZShzW2tdICE9ICdcMCcgJiYgc1trXSAhPSAnXG4nKQogICAgICAgIGsrKzsKICAgIHJldHVybiBrOwp9CgppbnQgbXlTdHJjbXAoY2hhciBzMVtdLCBjaGFyIHMyW10pCnsKICAgIGlmKHMxWzBdID09ICdcbicgfHwgczFbMF0gPT0gJ1wwJykKICAgICAgICByZXR1cm4gMDsKICAgIHJldHVybiAxOwp9Cgp2b2lkIFN0cmluZ1JldmVyc2UoY2hhciBzdFtdKQp7CiAgICBpbnQgbGVuID0gbXlTdHJsZW4oc3QsIGxlbiksIHRlbXA7CiAgICBib29sIGNoZWNrID0gdHJ1ZTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBsZW47IGkrKykKICAgICAgICBpZihzdFtpXSA9PSAnICcpCiAgICAgICAgewogICAgICAgICAgICBjaGVjayA9IGZhbHNlOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICBpZihjaGVjaykKICAgIHsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspCiAgICAgICAgICAgIGNvdXQgPDwgc3RbaV07CiAgICAgICAgc3RbMF0gPSAnXDAnOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGZvcih0ZW1wID0gbGVuIC0gMTsgdGVtcCA+PSAwOyB0ZW1wLS0pCiAgICB7CiAgICAgICAgaWYoc3RbdGVtcF0gPT0gJyAnKQogICAgICAgICAgICBicmVhazsKICAgIH0KICAgIGZvcihpbnQgaSA9IHRlbXAgKyAxOyBpIDwgbGVuOyBpKyspCiAgICAgICAgY291dCA8PCBzdFtpXTsKICAgIGNvdXQgPDwgJyAnOwogICAgZm9yKGludCBpID0gdGVtcDsgaSA+PSAwOyBpLS0pCiAgICAgICAgaWYoc3RbaV0gPT0gJyAnKQogICAgICAgICAgICBmb3IoaW50IGogPSBpIC0gMTsgaiA+PSAwOyBqLS0pCiAgICAgICAgICAgICAgICBpZihzdFtqXSA9PSAnICcpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgZm9yKGludCBrID0gaiArIDE7IGsgPCBpOyBrKyspCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8IHN0W2tdOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpID0gajsKICAgICAgICAgICAgICAgICAgICBjb3V0IDw8ICcgJzsKICAgICAgICAgICAgICAgIH0KICAgIHRlbXAgPSAwOwogICAgd2hpbGUoc3RbdGVtcF0gIT0gJyAnKQogICAgICAgIGNvdXQgPDwgc3RbdGVtcCsrXTsKICAgIHN0WzBdID0gJ1wwJzsKICAgIHJldHVybjsKfQ==