谁能帮帮小弟,小程序题 
a2 b 5e3 42 6 fg0z y w32 10 p q39rs 
`从键盘输入以上数据,进行排序后,输出结果 
1 abb bee eee e44 
2 446 66f gzy w22 
3 220 0pq 999 9rs 方法:1.把输入的字符串中的英文字母直接输出 
2.遇到数字(n)的情况下,不输出数字,把数字后面的字符串输出n+1回 
3.每一行前面显示行数,一行分4组,1组3个字符。 
 

解决方案 »

  1.   

    String str = "a2 b 5e3 42 6 fg0z y w32 10 p q39rs ";
    StringBuffer result = new StringBuffer();

    str = str.replaceAll("\\s","");
    System.out.println(str);
    for(; str.length() > 1;){
    String sub_1 = str.substring(0,1);
    String sub_2 = str.substring(1,2);
    Pattern pt = Pattern.compile("[0-9]");
    Matcher m = pt.matcher(sub_1);
    if(m.matches() == true){
    for(int i = 0; i <= Integer.parseInt(sub_1); i++){
    result.append(sub_2);
    }
    str = str.substring(2);
    }else{
    result.append(sub_1);
    str = str.substring(1);
     int a=1;
    }
    }

    result.append(str);
    System.out.println(result);
    boolean flag = true;
    for(int i = 0;flag == true; i++){
    System.out.print(i+1);
    for(int j =0; j <= 3; j++){
    if (result.toString().length() <= 3){
    System.out.print(" " + result);
    flag = false;
    j = 3;
    }else{
    System.out.print(" " + result.substring(0,3));
    }
    result = result.replace(0,result.toString().length() <= 3?result.toString().length():3,"");
    }
    System.out.println();
    }
      

  2.   

    public class test5
    {
    private String text;
    private char[] ch;
    private static int m,n;
    private int row;

    public test5()
    {
    text = "a2 b 5E3 42 6 fg0z y w32 10 p q39rS";
    text = text.trim().toLowerCase().replaceAll(" ","");
    ch = text.toCharArray();
    m = n = 0;
    row = 1;
    }
    public void print()
    {
    boolean hasnextrow;//是否打印下一个行号
    for (int i = 0; i < ch.length; i++)
    {
    hasnextrow = (i+1 < ch.length);
    if ((ch[i]>='a')&&(ch[i]<='z'))
    print(ch[i], hasnextrow);
    if ((ch[i]>='0')&&(ch[i]<='9'))
    {
    int num = ch[i] - '0';
    i++;
    hasnextrow = (i+1 < ch.length);
    if (i < ch.length)
    for (int j = 0; j <=num; j++)
    print(ch[i], hasnextrow);
    }
    }
    }
    public void print(char ch, boolean b)
    {
    if (m == 0)
    System.out.print(row + " ");
    m ++;
    System.out.print(ch);
    if (m % 3 == 0)
    {
    n ++;
    if (n % 4 == 0)
    {
    row ++;
    System.out.println();
    if (b)
    System.out.print(row + " ");
    }
    else
    System.out.print(" ");
    }
    }
    public static void main(String[] args)
    {
    test5 t = new test5();
    t.print();
    }
    }