题解 | #多组_带空格的字符串_T组形式#
多组_带空格的字符串_T组形式
https://www.nowcoder.com/practice/cff28a28d7f54419a640a8bb19f4275f
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int num = in.nextInt(); String[] strs = new String[num]; for(int i = 0;i < num;i++){ int len = in.nextInt(); //消耗掉换行符 in.nextLine(); //此时才能正确读取一行的字符串内容 strs[i] = in.nextLine(); } for(String str : strs){ for(int j = str.length() - 1;j >= 0;j--){ char c = str.charAt(j); if(c != ' '){ System.out.print(c); } } System.out.println(); } } }