# format string
# contoh generic

# string
nama = "martin"
format_str = f"hello {nama}"
print(format_str)

# boolean
boolean = True
format_str = f"boolean = {boolean}"
print(format_str)

# angka desimal
angka = 2005.5
format_str = f"angka = {angka}"
print(format_str)

# angka desimal -> .2f menunjukan 2 angka dibelakang koma
angka = 2005.54321
format_str = f"desimal = {angka:.2f}"
print(format_str)

# bilangan bulat
angka = 15
format_str = f"bilangan bulat = {angka:d}"
print(format_str)

# bilangan dengan ordo ribuan // jutaan
angka = 2000000
format_str = f"jutaan = {angka:,}"
print(format_str)

# menampilkan tanda + atau -
angka_minus = -10
angka_plus = 10
format_minus = f"minus = {angka_minus:+d}"
format_plus = f"plus = {angka_plus:+d}"

print(format_minus)
print(format_plus)

# format persen
persentase = 0.045
format_persen = f"persen = {persentase:.2%}"
print(format_persen)

# melakukan operasi aritmatika di dalam placeholder
harga = 10000
jumlah = 5
format_string = f"harga total = Rp. {harga*jumlah:,}"
print(format_string)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Roman Moser, 4/25/19

"""
Test BST2 (Binary Search Tree)
BST2 code includes:
    * status for node (True/False)
    * deleteFalse operation that deletes all nodes of BST2 with status=False
"""

#import os
#os.chdir('/home/roman/Documents/HU/CISC610_DataStructures/Assignments/Assignment3_Sort_BST')
from BST2 import BST2

def main():
    print('create BST with elements: 10, 5, 2, 6, 1, 4, 20, 15')
    print('(Nodes with key 6, 4 and 20 have status=False)')
    bst = BST2(10, True)
    bst.insert(5, True)
    bst.insert(2, True)
    bst.insert(6, False)
    bst.insert(1, True)
    bst.insert(4, False)
    bst.insert(20, False)
    bst.insert(15, True)
    print('traverse tree in order and print all keys (expected output: 1, 2, 4, 5, 6, 10, 15, 20):')
    bst.traverseInOrder()
    print('delete nodes with status=False and traverse tree (expected output: 1, 2, 5, 10, 15)')
    bst.deleteFalse()
    bst.traverseInOrder()

if __name__ == '__main__':
    main()


#!/usr/bin/env python
# encoding: utf-8

'''
# @Time    : 2022/2/27 19:04
# @Author  : yq
# @File    : 383赎金信.py
# @Software: PyCharm

'''

# 题目
# 给你两个字符串：ransomNote 和 magazine ，判断 ransomNote 能不能由 magazine 里面的字符构成。
#
#  如果可以，返回 true ；否则返回 false 。

class Solution:
    def canConstruct(self, ransomNote, magazine):
        record = [0] * 26
        # 交换顺序
        for i in range(len(magazine)):
            record[ord(magazine[i]) - ord('a')] += 1

        for i in range(len(ransomNote)):
            record[ord(ransomNote[i]) - ord('a')] -= 1

        for i in range(26):
            if record[i] < 0:
                return False
                break
        return True

if __name__ == '__main__':
    a = Solution()
    temp = a.canConstruct("aa","aab")
    print(temp)

3哈希表/1有效的字母异位词/383赎金信.py