http://codeforces.com/contest/1285/problem/A
A. Mezo Playing Zoma
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Today, Mezo is playing a game. Zoma, a character in that game, is initially at position x=0x=0. Mezo starts sending nn commands to Zoma. There are two possible commands:
- 'L' (Left) sets the position x:=x−1x:=x−1;
- 'R' (Right) sets the position x:=x+1x:=x+1.
Unfortunately, Mezo's controller malfunctions sometimes. Some commands are sent successfully and some are ignored. If the command is ignored then the position xx doesn't change and Mezo simply proceeds to the next command.
For example, if Mezo sends commands "LRLR", then here are some possible outcomes (underlined commands are sent successfully):
- "LRLR" — Zoma moves to the left, to the right, to the left again and to the right for the final time, ending up at position 00;
- "LRLR" — Zoma recieves no commands, doesn't move at all and ends up at position 00 as well;
- "LRLR" — Zoma moves to the left, then to the left again and ends up in position −2−2.
Mezo doesn't know which commands will be sent successfully beforehand. Thus, he wants to know how many different positions may Zoma end up at.
Input
The first line contains nn (1≤n≤105)(1≤n≤105) — the number of commands Mezo sends.
The second line contains a string ss of nn commands, each either 'L' (Left) or 'R' (Right).
Output
Print one integer — the number of different positions Zoma may end up at.
처음으로 코드포스에 접속해서 지난 대회 문제풀이 도전!!했습니다. ㅎㅎ
처음에 뒷부분 해석을 안하고 번역기 돌리고.,. 랜덤함수로 발생시켜서,, LRLR 읽은대로 동작하게했습니다.
에러-0-.!!. 아..문제대로 답을 만드는게 아니고,,..;나올수있는 경우의 수의 합이구나...;; 영어의 장벽 느끼곤 ㅎㅎ
열심히 생각해봅니다... 그럼 LR 상관없이 문자열.length + 1을 하면 답이 나옵니다. (이동 거리값 +1)이 되므로..
해답코드
package solution;
import java.util.Scanner;
public class CodeForce_Zoma {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int Max =0;
String move = "";
Max= Integer.parseInt(sc.nextLine());
move =sc.nextLine();
sc.close();
System.out.println(move.length()+1);
}//메인메소드종료
}//클래스종료
'IT_tech > 알고리즘' 카테고리의 다른 글
백준)2292 벌집 - 자바 (0) | 2020.05.31 |
---|---|
백준)3052 나머지 - JAVA (0) | 2020.01.28 |
백준 2562번) 최댓값 - 자바 (0) | 2019.11.19 |
백준 10818) 최소,최대 -자바 (0) | 2019.11.12 |
백준 10951) A+B - 4 자바 (0) | 2019.11.05 |