ブリブリ備忘録 おっ、python

HackerRankの問題とコメント(python3) 拙いですが...

2018-09-01から1ヶ月間の記事一覧

String Formatting

・問題 Given an integer, , print the following values for each integer from to : Decimal Octal Hexadecimal (capitalized) Binary The four values must be printed on a single line in the order specified above for each from to . Each value sho…

Designer Door Mat

・問題 Mr. Vincent works in a door mat manufacturing company. One day, he designed a new door mat with the following specifications: Mat size must be X. ( is an odd natural number, and is times .) The design should have 'WELCOME' written i…

Text Wrap

・問題 You are given a string and width . Your task is to wrap the string into a paragraph of width . Input Format The first line contains a string, . The second line contains the width, . Constraints Output Format Print the text wrapped p…

Text Alignment

・問題 In Python, a string of text can be aligned left, right and center. .ljust(width) This method returns a left aligned string of length width. >>> width = 20 >>> print 'HackerRank'.ljust(width,'-') HackerRank---------- .center(width) T…

String Validators

・問題 Python has built-in string validation methods for basic data. It can check if a string is composed of alphabetical characters, alphanumeric characters, digits, etc. str.isalnum() This method checks if all the characters of a string …

Find a string

・問題 In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left. NOTE: Str…

Mutations

・問題 We have seen that lists are mutable (they can be changed), and tuples are immutable (they cannot be changed). Let's try to understand this with an example. You are given an immutable string, and you want to make changes to it. Examp…

What's Your Name?

・問題 You are given the firstname and lastname of a person on two different lines. Your task is to read them and print the following: Hello firstname lastname! You just delved into python. Input Format The first line contains the first na…

String Split and Join

・問題 In Python, a string can be split on a delimiter. Example: >>> a = "this is a string" >>> a = a.split(" ") # a is converted to a list of strings. >>> print a ['this', 'is', 'a', 'string'] Joining a string is simple: >>> a = "-".join(…

sWAP cASE

・問題 You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa. For Example: Www.HackerRank.com → wWW.hACKERrANK.COM Pythonist 2 → pYTHONIST 2 Input Format A …