Created
January 15, 2021 07:45
-
-
Save seriwb/6b53d965f694bbc6f5e25ff6630e7df6 to your computer and use it in GitHub Desktop.
指定の文字列が入力文字列で何個登場するかを返却するプログラム。 前後の文字列をつなげた場合に指定の文字列が登場する場合も、カウントする。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
MIN = 1 | |
MAX = 100 | |
CHECKS = "watashihanoone" | |
def main(): | |
argvs = sys.argv | |
argc = len(argvs) | |
if (argc == 2): | |
input_data = argvs[1] | |
if not (input_data and len(input_data) >= MIN and len(input_data) <= MAX): | |
print(f'入力可能文字数は{MIN}以上{MAX}以下です') | |
exit(-1) | |
else: | |
print('パラメータが不正です') | |
exit(-1) | |
result = 0 | |
if len(input_data) >= len(CHECKS): | |
add_position = len(CHECKS) - 1 | |
result = f'{input_data}{input_data[:add_position]}'.count(CHECKS) | |
print(result) | |
return result | |
if __name__ == '__main__': main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment