#include <iostream> #include <map> using namespace std; int main() { string str; cin >> str; map<char, int> dict; for (char c:str) { auto it = dict.find(c); if (it != dict.end()) { dict[c]++; } else { dict[c] = 1; } } // 重新排列字母,默认就是a-z排列 string res; for (auto entry:dict) { int i = entry.second; while (i-- > 0) { res.push_back(entry.first); } } cout << res << endl; }
import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String str=sc.nextLine(); char array[]=str.toCharArray(); Arrays.sort(array); for(int i=0;i<array.length;i++) System.out.print(array[i]); System.out.println(); } sc.close(); } }
#include <stdio.h> #include <string.h> typedef int Position; // 快排 Position partion(char *str, int low, int high) { char pivot = str[low]; while (low < high) { while (low < high && str[high] >= pivot) high--; str[low] = str[high]; while (low < high && str[low] <= pivot) low++; str[high] = str[low]; } str[low] = pivot; return low; } void QuickSort(char *str, int low, int high) { if (low < high) { Position pivotProps = partion(str, low, high); QuickSort(str, low, pivotProps - 1); QuickSort(str, pivotProps + 1, high); } } int main() { char str[200]; while (scanf("%s", str) != EOF) { // 注意 while 处理多个 case QuickSort(str, 0, strlen(str) - 1); printf("%s", str); } return 0; }
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); char[] array = scanner.nextLine().toCharArray(); Arrays.sort(array); for (char c : array) { System.out.print(c); } } }
#include<bits/stdc++.h> using namespace std; int main(){ char ch[201]; while(cin>>ch){ sort(ch,ch+strlen(ch)); cout<<ch<<endl; } }
#include<stdio.h> #include<stdlib.h> #include<string.h> int c(const void*a,const void*b){return *(char*)a-*(char*)b;} int main (){//the shorter,the better. int n;char s[200]; for(;~scanf("%s",s)&&(qsort(s,strlen(s),sizeof(char),c),printf("%s\n",s));); }
#include <iostream> #include <algorithm> using namespace std; bool cmp(char a,char b){ return a < b; } int main() { string str; cin >> str; int len = str.length(); char* s = new char[len]; for(int i = 0;i < len; i++){ s[i] = str[i]; } sort(s, s + len, cmp); puts(s); }