Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstring>
- #include <algorithm>
- #include <iostream>
- #include <fstream>
- using namespace std ;
- char x[231];
- int compare (const void * a, const void * b)
- {
- return *(char*)a-*(char*)b;
- }
- void reverse(char word[])
- {
- int len=strlen(word);
- for (int i=0;i<len/2;i++)
- {
- word[i]^=word[len-i-1];
- word[len-i-1]^=word[i];
- word[i]^=word[len-i-1];
- }
- }
- int main()
- {
- char x2[231];
- char x3[231];
- scanf("%300s",x);
- if (strlen(x) % 2 == 0)
- {
- strncpy(x2,x,strlen(x)/2);
- qsort (x2,strlen(x2),1,compare);
- reverse(x2);
- strncpy(x3,x,strlen(x)/2);
- qsort (x3,strlen(x3),1,compare);
- cout << x2 << x3;
- }
- else if (strlen(x) % 2 != 0)
- {
- int lenght = strlen(x);
- int t1 = lenght/2;
- strncpy(x2,x,strlen(x)/2);
- qsort (x2,strlen(x2),1,compare);
- reverse(x2);
- strncpy(x3,x,strlen(x)/2);
- qsort (x3,strlen(x3),1,compare);
- cout << x2 << x[(strlen(x)/2)] << x3;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement