ブリブリ備忘録 おっ、python

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

itertools.product()

・問題 itertools.product() This tool computes the cartesian product of input iterables. It is equivalent to nested for-loops. For example, product(A, B) returns the same as ((x,y) for x in A for y in B). Sample Code >>> from itertools impo…

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 …

Detect Floating Point Number

・問題 You are given a string . Your task is to verify that is a floating point number. In this task, a valid float number must satisfy all of the following requirements: Number can start with +, - or . symbol. For example: ✔+4.50 ✔-1.0 ✔.…

Tuples 配列とタプルの違いや、標準入力から配列を作成する方法

・問題 Task Given an integer, , and space-separated integers as input, create a tuple, , of those integers. Then compute and print the result of . Note: hash() is one of the functions in the __builtins__ module, so it need not be imported.…

Lists 配列の様々な操作(追加や削除など)

・問題 Consider a list (list = []). You can perform the following commands: insert i e: Insert integer at position . print: Print the list. remove e: Delete the first occurrence of integer . append e: Insert integer at the end of the list.…

Finding the percentage 少数第二位まで出力する方法

・問題 You have a record of students. Each record contains the student's name, and their percent marks in Maths, Physics and Chemistry. The marks can be floating values. The user enters some integer followed by the names and marks for stud…

Write a function 関数の定義

・問題 We add a Leap Day on February 29, almost every four years. The leap day is an extra, or intercalary day and we add it to the shortest month of the year, February. In the Gregorian calendar three criteria must be taken into account t…

Nested Lists 二重配列

・問題 Given the names and grades for each student in a Physics class of students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade. Note: If there are multiple students with the same grade…

Find the Runner-Up Score!  リスト 削除

・問題 Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given scores. Store them in a list and find the score of the runner-up. Input Format The first line contains .…

List Comprehensions for文 if文

・問題 Let's learn about list comprehensions! You are given three integers and representing the dimensions of a cuboid along with an integer . You have to print a list of all possible coordinates given by on a 3D grid where the sum of is n…

Polar Coordinates  複素数

・問題 A complex number z=x+yj is completely determined by its real part and imaginary part . Here, is the imaginary unit. A polar coordinate () is completely determined by modulus and phase angle .If we convert complex number to its polar…

Print Function import math

・問題 Read an integer . Without using any string methods, try to print the following: Note that "" represents the values in between. Input Format The first line contains an integer . Output Format Output the answer as explained in the tas…

Loops for文,rangeについて

・問題 Task Read an integer . For all non-negative integers , print . See the sample for details. Input Format The first and only line contains the integer, . Constraints Output Format Print lines, one corresponding to each . Sample Input …

Python: Division

・問題 Task Read two integers and print two lines. The first line should contain integer division, // . The second line should contain float division, / . You don't need to perform any rounding or formatting operations. Input Format The fi…

Arithmetic Operators input関数

・問題 Task Read two integers from STDIN and print three lines where: The first line contains the sum of the two numbers. The second line contains the difference of the two numbers (first - second). The third line contains the product of t…

Python If-Else if-elif-else

・問題 Given an integer, , perform the following conditional actions: If is odd, print Weird If is even and in the inclusive range of to , print Not Weird If is even and in the inclusive range of to , print Weird If is even and greater tha…

Say "Hello, World!" With Python print関数

・問題 Here is a sample line of code that can be executed in Python: print("Hello, World!") You can just as easily store a string as a variable and then print it to stdout: my_string = "Hello, World!" print(my_string) The above code will p…

Solve Me First 関数の定義

・問題 Complete the function solveMeFirst to compute the sum of two integers. Function prototype: int solveMeFirst(int x, int y); where, x is the first integer input. y is the second integer input Return values sum of the above two integer…

最初

hackerrankの問題、ソースコード等を振り返れるように、苦労した点、重要点などをまとめます。