You Can Go Your Own Way
原题: https://codingcompetitions.withgoogle.com/codejam/round/0000000000051705/00000000000881da
1 |
直接替换S和E. 我看分析的证明好长啊, 我是举例试出来的. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = Integer.valueOf(scanner.nextLine()); for (int i = 1; i <= n; i++) { String res = solve(Integer.valueOf(scanner.nextLine()), scanner.nextLine()); System.out.println("Case #" + i + ": " + res); } } private static String solve(int n, String direction) { StringBuilder sb = new StringBuilder(); for(int i = 0; i < direction.length(); i++) { if (direction.charAt(i) == 'E') { sb.append('S'); } else { sb.append('E'); } } return sb.toString(); } } |