大明子又称小码哥

大明子又称小码哥

题目描述

输入描述

输出描述

用例

具体解析看代码逻辑

示例代码

package com.bytesoc.calc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class T71 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		List<Integer> orderList = new ArrayList<>();
		Map<Integer, String> wordMap = new HashMap<Integer, String>();
		String input = sc.nextLine();
		String wordArr[] = input.split(" ");
		for (int i = 0; i < wordArr.length; i++) {
			String word = wordArr[i];
			// 截取尾部的数字
			String numStr = "";
			String last = word.charAt(word.length() - 1) + "";
			Integer number = -1;
			try {
				while (word.length() > 0) {
					int nS = Integer.parseInt(last);
					numStr = nS + numStr;
					StringBuilder sb = new StringBuilder(word);
					sb.setCharAt(word.length() - 1, ' ');
					word = sb.toString().trim();
					last = word.charAt(word.length() - 1) + "";
				}
			} catch (Exception e) {
				number = Integer.parseInt(numStr);
			}
			String content = word.replace(numStr, "");
			orderList.add(number);
			wordMap.put(number, content);
		}
		orderList.sort((a, b) -> a - b);
		for (Integer key : orderList) {
			System.out.print(wordMap.get(key) + " ");
		}
	}
}


执行结果:

华为OD机试之报文重排序(Java源码)-LMLPHP

08-05 16:24