公式
A - Vacation Validation 解説 by en_translator
For beginners
- If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
- Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
- 「Python入門 AtCoder Programming Guide for beginners (APG4bPython)」 is a Python tutorial for competitive programmers. Again, this is only in Japanese.
Use a for
statement to inspect the \(L\)-th through \(R\)-th characters of \(S\). Once you find x
, you may print No
and terminate the program right away; this makes the implementation easier.
Note that in most programming languages, the index of a string or an array starts with \(0\).
Sample code (Python)
N, L, R = map(int,input().split())
S = input()
for i in range(L-1, R):
if S[i] == 'x':
print("No")
exit()
print("Yes")
この他、「~の全てが~か?」などの判定を行うことができるメソッドを用いたり、文字列として比較するなどの方法により、for文を明示的に使うことなく解くこともできます。
Alternatively, you can implement it without using a for
statement, by using a method that can check if “does all of them satisfy this condition?” or using string comparison.
Sample code (Python)
N, L, R = map(int,input().split())
S = input()
if all(c == 'o' for c in S[L-1:R]):
print("Yes")
else:
print("No")
Sample code (Python)
N, L, R = map(int,input().split())
S = input()
if S[L-1:R] == "o" * (R-L+1):
print("Yes")
else:
print("No")
投稿日時:
最終更新: