#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgTUFYIDMwMAoKaW50IG15U3RyY21wKGNoYXIgczFbXSwgY2hhciBzMltdKTsKaW50IG15U3RybGVuKGNoYXIgc1tdLCBpbnQgayk7CnZvaWQgbXlTdHJjcHkoY2hhciBzW10sIGludCB2dCwgY2hhciBzMVtdLCBpbnQgayk7CnZvaWQgbXlTdWJzdHIoY2hhciBzW10sIGludCBiLCBpbnQgY291bnQsIGNoYXIgc3NbXSk7CmJvb2wgbXlTdHJjYXQoY2hhciBzMVtdLCBjaGFyIHMyW10pOwp2b2lkIFN0cmluZ1JldmVyc2UoY2hhciBzdFtdKTsKCmludCBtYWluKCkKewogICAgY2hhciBzW01BWF07CiAgICBmZ2V0cyhzLCAzMDAsIHN0ZGluKTsKICAgIGlmKG15U3RyY21wKHMsICIiKSA9PSAwKQogICAgICAgIGNvdXQgPDwgIkNodW9pIHJvbmcuIiA8PCBlbmRsOwogICAgZWxzZQogICAgewogICAgICAgIFN0cmluZ1JldmVyc2Uocyk7CiAgICAgICAgY291dCA8PCBzIDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQoKaW50IG15U3RybGVuKGNoYXIgc1tdLCBpbnQgaykKewogICAgayA9IDA7CiAgICB3aGlsZShzW2tdICE9ICdcMCcgJiYgc1trXSAhPSAnXG4nKQogICAgICAgIGsrKzsKICAgIHJldHVybiBrOwp9CgppbnQgbXlTdHJjbXAoY2hhciBzMVtdLCBjaGFyIHMyW10pCnsKICAgIGlmKHMxWzBdID09ICdcbicgfHwgczFbMF0gPT0gJ1wwJykKICAgICAgICByZXR1cm4gMDsKICAgIHJldHVybiAxOwp9Cgp2b2lkIFN0cmluZ1JldmVyc2UoY2hhciBzdFtdKQp7CiAgICBpbnQgbGVuID0gbXlTdHJsZW4oc3QsIGxlbiksIHRlbXA7CiAgICBib29sIGNoZWNrID0gdHJ1ZTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBsZW47IGkrKykKICAgICAgICBpZihzdFtpXSA9PSAnICcpCiAgICAgICAgewogICAgICAgICAgICBjaGVjayA9IGZhbHNlOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICBpZihjaGVjaykKICAgIHsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspCiAgICAgICAgICAgIGNvdXQgPDwgc3RbaV07CiAgICAgICAgc3RbMF0gPSAnXDAnOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGZvcih0ZW1wID0gbGVuIC0gMTsgdGVtcCA+PSAwOyB0ZW1wLS0pCiAgICB7CiAgICAgICAgaWYoc3RbdGVtcF0gPT0gJyAnKQogICAgICAgICAgICBicmVhazsKICAgIH0KICAgIGZvcihpbnQgaSA9IHRlbXAgKyAxOyBpIDwgbGVuOyBpKyspCiAgICAgICAgY291dCA8PCBzdFtpXTsKICAgIGNvdXQgPDwgJyAnOwogICAgZm9yKGludCBpID0gdGVtcDsgaSA+PSAwOyBpLS0pCiAgICAgICAgaWYoc3RbaV0gPT0gJyAnKQogICAgICAgICAgICBmb3IoaW50IGogPSBpIC0gMTsgaiA+PSAwOyBqLS0pCiAgICAgICAgICAgICAgICBpZihzdFtqXSA9PSAnICcpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgZm9yKGludCBrID0gaiArIDE7IGsgPCBpOyBrKyspCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8IHN0W2tdOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpID0gajsKICAgICAgICAgICAgICAgICAgICBjb3V0IDw8ICcgJzsKICAgICAgICAgICAgICAgIH0KICAgIHRlbXAgPSAwOwogICAgd2hpbGUoc3RbdGVtcF0gIT0gJyAnKQogICAgICAgIGNvdXQgPDwgc3RbdGVtcCsrXTsKICAgIHN0WzBdID0gJ1wwJzsKICAgIHJldHVybjsKfQ==