문제 : https://codeforces.com/contest/1567/problem/A
뭔가 복잡해보이지만, 그냥 쭉 보면서 D -> U, U -> D, L과 R은 그대로 출력하면 된다.
코드 : github
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
while (t-->0) {
int n = Integer.parseInt(br.readLine());
String s = br.readLine();
for (int i = 0; i < n; i++) {
char c = s.charAt(i);
if (c == 'D') sb.append('U');
else if (c == 'U') sb.append('D');
else sb.append(c);
}
sb.append('\n');
}
System.out.print(sb);
}
}
'PS > CodeForces' 카테고리의 다른 글
CodeForces 1614B - Divan and a New Project (Java) (0) | 2021.11.27 |
---|---|
CodeForces 1593A - Elections (Java) (0) | 2021.11.27 |
CodeForces 1569B - Chess Tournament (Java) (0) | 2021.11.27 |
CodeForces 1569A - Balanced Substring (Java) (0) | 2021.11.27 |
CodeForces 4A - Watermelon (Java) (0) | 2021.11.27 |
댓글