import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Solution { public String trans(String s, int n) { // write code here if (s == null || s.length() < 1 || n < 1) { } char[] arr = s.toCharArray(); for (int i = 0; i < n; i++) { if (arr[i] >= 'a' && arr[i] <= 'z') { arr[i] = (char) (arr[i] - 'a' + 'A'); } else if (arr[i] >= 'A' && arr[i] <= 'Z') { arr[i] = (char) (arr[i] - 'A' + 'a'); } } reverse(arr, 0, n - 1); for (int i = 0; i < n; i++) { int j = i; while (j < n && arr[j] != ' ') { j++; } if (j != i) { reverse(arr, i, j - 1); } i = j; } return new String(arr); } private void reverse(char[] arr, int i, int j) { while (i < j) { char tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; i++; j--; } } }