题解 | 多组_带空格的字符串_T组形式
多组_带空格的字符串_T组形式
https://www.nowcoder.com/practice/cff28a28d7f54419a640a8bb19f4275f
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
for(int i = 0;i<t;i++){
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
String result = reverseString(s);
System.out.println(result);
}
sc.close();
}
public static String reverseString(String s){
String nospace = s.replaceAll(" ","");
StringBuilder sb = new StringBuilder(nospace);
return sb.reverse().toString();
}
}



查看12道真题和解析