鱼C论坛

 找回密码
 立即注册
查看: 3007|回复: 5

有大佬帮忙看一道题吗

[复制链接]
发表于 2021-3-7 01:22:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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.

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-3-7 08:30:32 | 显示全部楼层
因为直接打字太麻烦所以我写在了纸上
file:///C:/Users/DELL/Desktop/%E5%87%BD%E6%95%B0same_pattern.jpg
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-3-7 08:31:04 | 显示全部楼层
怎么发图片啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-3-7 08:34:10 | 显示全部楼层

                               
登录/注册后可看大图
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-3-7 08:35:16 | 显示全部楼层
好吧一开始我以为是电脑存储地址。。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-3-7 14:42:41 | 显示全部楼层
  1. def same_pattern(a,b):
  2.     la,lb = len(a),len(b)
  3.     if la == lb == 1:
  4.         return True
  5.     if la != lb:
  6.         return False
  7.     for i in range(la):
  8.         if not a.index(a[i]) == b.index(b[i]):
  9.             return False
  10.             break
  11.     else:
  12.         return True
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-27 01:07

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表