fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. char t[1000];
  4. void rxSort(char s[]){
  5. int n=0,i, d,c, cnt[32];
  6. for(d=1;d>-1;d--){
  7. for(i=0;i<32;i++){
  8. cnt[i]=0;
  9. }
  10. i=0;
  11. while(s[2*i]){
  12. //printf("%c=%d\n",s[2*i],s[2*i]-97);
  13. cnt[s[2*i+d]-97]++;
  14. i++;
  15. }
  16. c=i;
  17. for(i=31;i>-1;i--){
  18. //printf(">%d=%d %d\n",i,cnt[i],c);
  19. c -= cnt[i];
  20. //printf(">>%d=%d %d\n",i,cnt[i],c);
  21. cnt[i]=c;
  22. //printf(">>>%d=%d %d\n",i,cnt[i],c);
  23. }
  24. i=0;
  25. while(s[2*i]){
  26. //printf(">>%c=%d %d\n",s[2*i+d],s[2*i+d]-97, cnt[s[2*i+d]-97]);
  27. t[2*cnt[s[2*i+d]-97]] = s[2*i];
  28. t[2*cnt[s[2*i+d]-97]+1] = s[2*i+1];
  29. cnt[s[2*i+d]-97]++;
  30. i++;
  31. }
  32. memcpy(s, t, 2*i);
  33. //printf("%s %s\n",t, s);
  34. }
  35. }
  36. int main(void) {
  37. int i;
  38. char s[1001];
  39. scanf("%d",&i);
  40. while(i--){
  41. scanf("%s", &s);
  42. rxSort(s);
  43. printf("%s\n",s);
  44. }
  45. return 0;
  46. }
  47. /*
  48. int n[500];
  49. void qsort(int left, int right, int pivot){
  50.  int t, l=left, r=right, p=pivot;
  51.  while(l<r){
  52.   while(n[l]<=n[p]&&l++<=r);
  53.   while(n[r]>n[p]&&r-->=l);
  54.   if(l>=r){
  55.   t=n[l]; n[l]=n[p]; n[p]=t;
  56.   qsort(left,l-1,l+(l-left)/2);
  57.   qsort(l+1,right,l+(right-l)/2);
  58.   }else{
  59.   t=n[l];n[l]=n[r]; n[r]=t;
  60.   }l++;r--;
  61.  }
  62. }
  63. int main(void) {
  64. int i, j,k;
  65. char s[1000];
  66. scanf("%d",&i);
  67. while(i--){
  68. scanf("%s", &s);
  69. j=0;
  70. while(s[2*j]){
  71. n[j] = s[2*j+1] + (s[2*j]<<8);j++;
  72.   }
  73.   qsort(0,j-1,j/2);
  74.   k=0;
  75.   while(k<j){
  76. printf("%c%c", n[k]>>8,n[k]);
  77. k++;
  78. }
  79. printf("\n");
  80. }
  81. return 0;
  82. }
  83. */
  84.  
Success #stdin #stdout 0s 2252KB
stdin
5
abbaaccb
dddcccbbbaaa
geegeegeegeebabybabybaby
oh
dkeodkcjdheudiedjskdjcdnfejhjsdfhbdjyrrngusbsyfittytifhrblwpwdjvytriebsvcsdztajdorphnfbdeiengbhjeedpsskhhaxmznxncndjsdffaghazfggrtayfgfsgsghssriobbhfdsegfsfdffaghazdkeodkcjdheudiedjskdjcdnfgsfgsfdgfafgacfhdkeodkcjdheudiedjskdjcdnfejhjsdfhbdjyrrngusbsyfittytifhrblwpwdjvytriebsvcsdztajdorphnfbdkeodkcjdheudiedjskdjcdnfejhjsdfhbdjyrrngusbsyfittytifhrblwpwdjvytriebsvcsdztajdorphnfbdeiengbhjeedpsskhhaxmznxncndjsdffaghazfggrtayfgfsgsghssriobbhfdsegfsfdffaghazdkeodkcjdheudiedjskdjcdnfgsfgsfdgfafgacfhdkeodkcjdheufrdweuiopdiedjskdjcdnfejhjsdfhbdjyrrngusbsyfittytifhrbiwpwdjvytriebsvcsdztajdorphnfbdeiengbhjeedpsskhhaxmznxncndjsdffaghazdkeodkcjdheudiedjskdjcdnfejhjsdfhbdjyrrngusbsyfittytifhrblwpwdjvytriebsvcsdztajdorphnfbdeiengbhjeedpsskhhaxmztayfgfsgsghssriobbhfdsegfsxncndjsdffaghazfggrtayfgfsgsghssriobbhfdsegfsfgsfgsfdgfafgacfhfggrtayfgfsgsghssriobbhfdsegfsfgsfgsfdgfafgacfhdeiengbhjeedpsskhhaxmznxncndjsdffaghazdkeodkcjdheudiedjsukdjcdnfejhjsdfhbdjyrrngusbsyfittytifhrblwpwdjvytriebsvcsdztajdorphnf
stdout
abacbacb
aababbccdcdd
babababybybyeeeeegeggege
oh
acafafafagagagagagajajaxayayayazazbbbbbdbdbdbdbdbhbhbhbhbiblblblbsbsbsbscdcdcfcfcfcjcjcjcjcncncncncncscscscsdedfdfdfdfdfdfdgdhdhdhdhdidididididjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdkdkdkdkdkdkdkdkdndndndndndndododpdpdpdpdsdsdzdzdzdzebebebebededededededeeeeeeeeegegeieieieiejejeneneneneoeoeoeoeueueueufafafafbfbfdfdfdfdfdfdfefefefefffffffffffgfgfgfgfgfgfgfgfgfhfhfhfhfhfififififsfsfsfsfsgagagagbgbgbgbgfgfgfgfgfgfgfgfggggggghghghghghgrgsgsgsgsgsgsgsguguguguhahahahahahahahahahbhbhbhbhdhdhdhehehehehfhfhhhjhjhjhjhjhjhnhnhrhrhrhrhshsieieieieieieififififioioititjcjcjcjcjcjcjdjdjdjdjdjdjdjdjejhjhjhjhjsjsjsjsjsjsjsjsjsjvjvjvjvjyjykckckckckdkdkdkdkdkdkekekekekhkhkhkhlwlwmznfnfnfnfnfnfngngngobobobododododopororororphphphphpspwpwrbrbrdriririririririrnrnrnrnrprprrrrrtrtrtsbsbsbsbsdsdsdsdsdsdsdsdsdsesesesfsfsfsfsfsfsfsgsgsgsgsksksksrsrsssssssssssssssusvsvsvsvsysysysytatatatatatatititrtrtttttttttytyudududufuiususvcvcvyvywdwdwdwdwewpwpwpwpxmxmxmxmxnxnxnxnxnyfyfyfyfyryryryrytytytytytytytytzdzdzfzfzfznznznznztzt