|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Write a function called same_pattern that returns true or false depending on whether two stringshave the same pattern of characters. More precisely, two strings have the same pattern if they are ofthe same length and if two characters in the first string are equal, if and only if the characters in thecorresponding positions in the second string are also equal. Below are some examples of patterns thatare the same and patterns that differ (keep in mind that the method should return the same value nomatter what order the two strings are passed). 1st String 2nd String Same Pattern? --------------- -------------- ------------------ "" "" True
"a" "x" True
"a" "ab" False
"ab" "ab" True
"aa" "xy" False
"aba" "+-+" True
"---" "aba" False
"abcabc" "zodzod" True
"abcabd" "zodzoe" True
"abcabc" "xxxxxx" False
"aaassscccn" "aaabbbcccd"
True "asasasasas" "xyxyxyxyxy" True
"ascneencsa" "aeiouuoiea" True
"aaassscccn" "aaabbbcccd" True
Your function should take two parameters: the two strings to compare. You are allowed to createnew strings, but otherwise you are not allowed to construct extra data structures to solve this problem(no list, set, dictionary, etc). You are limited to the string functions on the cheat sheet.
|
|