aboutsummaryrefslogtreecommitdiff
path: root/challenge-092/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2021-03-15 18:18:09 +0800
committer冯昶 <seaker@qq.com>2021-03-15 18:18:09 +0800
commit5ed25077fde85262036c9db3e893d70ae0907b5c (patch)
tree8932d25b3fa6076e2d91ab2a331d4d8bfff20544 /challenge-092/paulo-custodio/python/ch-1.py
parent8b6be37fe4dac8b4c6489a95e55514b76b298d15 (diff)
parent65d54d52500028ec5359a7d39619803ade281543 (diff)
downloadperlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.tar.gz
perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.tar.bz2
perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-092/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-092/paulo-custodio/python/ch-1.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-092/paulo-custodio/python/ch-1.py b/challenge-092/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..70e334812e
--- /dev/null
+++ b/challenge-092/paulo-custodio/python/ch-1.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+
+# Challenge 092
+#
+# TASK #1 > Isomorphic Strings
+# Submitted by: Mohammad S Anwar
+# You are given two strings $A and $B.
+#
+# Write a script to check if the given strings are Isomorphic. Print 1 if they
+# are otherwise 0.
+#
+# Example 1:
+# Input: $A = "abc"; $B = "xyz"
+# Output: 1
+# Example 2:
+# Input: $A = "abb"; $B = "xyy"
+# Output: 1
+# Example 3:
+# Input: $A = "sum"; $B = "add"
+# Output: 0
+
+import sys
+
+def isomorphic(a,b):
+ if len(a)!=len(b):
+ return 0
+ else:
+ mapping = {}
+ mapped = {}
+ for i in range(0, len(a)):
+ if not a[i] in mapping: # a is new
+ if b[i] in mapped: # b already mapped to some other a
+ return 0
+ else: # store mapping
+ mapping[a[i]] = b[i]
+ mapped[b[i]] = 1
+ else: # a already occurred
+ if mapping[a[i]]!=b[i]: # previous mapping is different
+ return 0
+ return 1
+
+print(isomorphic(sys.argv[1], sys.argv[2]))