-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sagar Paul
committed
Jun 16, 2021
1 parent
176503e
commit 390562a
Showing
3 changed files
with
118 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class BST: | ||
|
||
def __init__(self,key): # Constractor of the class | ||
self.key = key | ||
self.lchild = None | ||
self.rchild = None | ||
|
||
# Insert Operation to a Binary Search Tree | ||
|
||
def insert(self, data): | ||
if self.key is None: | ||
self.key = data | ||
return | ||
elif self.key == data: | ||
return | ||
elif self.key > data: | ||
if self.lchild: | ||
self.lchild.insert(data) | ||
else: | ||
self.lchild = BST(data) | ||
return | ||
elif self.key < data: | ||
if self.rchild: | ||
self.rchild.insert(data) | ||
else: | ||
self.rchild = BST(data) | ||
return | ||
|
||
# Search a node in a binary Search Tree | ||
|
||
def search(self, data): | ||
if self.key is None: | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
d = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000} | ||
n = input() # CMXCVIII = 998 | ||
ans = d[n[0]] | ||
for i in range(1,len(n)): | ||
if d[n[i-1]] < d[n[i]]: | ||
ans += d[n[i]] - d[n[i-1]]*2 | ||
else: | ||
ans += d[n[i]] | ||
|
||
print(ans) |