Lily上课时使用字母数字图片教小朋友们学习英语单词,每次都需要把这些图片按照大小(ASCII码值从小到大)排列收好。请大家给Lily帮忙,通过代码解决。
Lily使用的图片使用字符"A"到"Z"、“a"到"z”、"0"到"9"表示。
示例1
输入:
Ihave1nose2hands10fingers
输出:
0112Iaadeeefghhinnnorsssv
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = sc.nextLine();
char[] ch = str.toCharArray();
Arrays.sort(ch);
for (char i : ch) {
System.out.print(i);
}
}
}
}
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = sc.nextLine();
int[] nums = new int[128];
for (int i = 0 ; i < str.length() ; i++) {
int j = str.charAt(i); //此时已经是转化为了ASC码来储存到数组
nums[j]++; //统计数组中ASC码出现次数
}
for (int a = 48 ; a < nums.length ; a++) { //从零开始输出
if (nums[a] != 0) {
for (int b = 0 ; b < nums[a] ; b++) {
System.out.print((char)a);
}
}
}
}
}
}