Skip to content

Commit 2621fa8

Browse files
Merge pull request #2672 from devgui01/main
Solve problem 1880: word equals summation
2 parents 3014a86 + 1bc0def commit 2621fa8

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def word_to_number(word: str) -> int:
2+
num_str = ""
3+
for ch in word:
4+
num_str += str(ord(ch) - ord("a"))
5+
return int(num_str)
6+
7+
8+
def is_sum_equal(firstWord: str, secondWord: str, targetWord: str) -> bool:
9+
return word_to_number(firstWord) + word_to_number(secondWord) == word_to_number(targetWord)
10+
11+
12+
if __name__ == "__main__":
13+
# Exemplos básicos para teste manual
14+
print(is_sum_equal("acb", "cba", "cdb")) # True
15+
print(is_sum_equal("aaa", "a", "aaaa")) # True
16+
print(is_sum_equal("a", "b", "c")) # False

0 commit comments

Comments
 (0)