Advertisement
pablo7890

Untitled

Jan 14th, 2013
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <cstring>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <fstream>
  5.  
  6. using namespace std ;
  7.  
  8. char x[231];
  9. int compare (const void * a, const void * b)
  10. {
  11.     return *(char*)a-*(char*)b;
  12. }
  13.  
  14. void reverse(char word[])
  15. {
  16.     int len=strlen(word);
  17.     for (int i=0;i<len/2;i++)
  18.     {
  19.         word[i]^=word[len-i-1];
  20.         word[len-i-1]^=word[i];
  21.         word[i]^=word[len-i-1];
  22.     }
  23. }
  24.  
  25. int main()
  26. {
  27.     char x2[231];
  28.     char x3[231];
  29.     scanf("%300s",x);
  30.    
  31.     if (strlen(x) % 2 == 0)
  32.     {
  33.         strncpy(x2,x,strlen(x)/2);
  34.         qsort (x2,strlen(x2),1,compare);
  35.         reverse(x2);
  36.                
  37.         strncpy(x3,x,strlen(x)/2);
  38.         qsort (x3,strlen(x3),1,compare);
  39.        
  40.         cout << x2 << x3;
  41.     }
  42.     else if (strlen(x) % 2 != 0)
  43.     {
  44.     int lenght = strlen(x);
  45.         int t1 = lenght/2;
  46.        
  47.         strncpy(x2,x,strlen(x)/2);
  48.         qsort (x2,strlen(x2),1,compare);
  49.         reverse(x2);
  50.        
  51.     strncpy(x3,x,strlen(x)/2);
  52.         qsort (x3,strlen(x3),1,compare);
  53.  
  54.         cout << x2 << x[(strlen(x)/2)] << x3;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement