当前位置: 首页 > news >正文

码蹄集:MT2045斐波那契,但是是字符串

现在有字符串组:
第0项a0=“IAKIOI”a0​=“IAKIOI”;
第1项a1=“WHENWILLSCORLLOFTAIWUCOMEOUT!!!”a1​=“WHENWILLSCORLLOFTAIWUCOMEOUT!!!”;
之后的第k项由第k−2k−2项+第k−1k−1项构成。
问第nn项字符串的第cc个字符是什么。

a0 = "IAKIOI"

a1 = "WHENWILLSCORLLOFTAIWUCOMEOUT!!!"

n, c = map(int, input().split())

# 迭代计算斐波那契字符串的长度

def fib_length(k):

    if k == 0:

        return len(a0)

    if k == 1:

        return len(a1)

    a, b = len(a0), len(a1)

    for _ in range(2, k + 1):

        a, b = b, a + b

    return a

# 迭代查找第n项的第c个字符

current_n = n

current_c = c - 1  # 转换为0索引

while True:

    if current_n == 0:

        print(a0[current_c])

        break

    if current_n == 1:

        print(a1[current_c])

        break

    # 计算前两项的长度

    len_k_minus_2 = fib_length(current_n - 2)

    if current_c < len_k_minus_2:

        # 字符在F(n-2)中

        current_n -= 2

    else:

        # 字符在F(n-1)中

        current_c -= len_k_minus_2

        current_n -= 1


文章转载自:
http://airmail.hfytgp.cn
http://cambium.hfytgp.cn
http://adrenochrome.hfytgp.cn
http://camail.hfytgp.cn
http://anabolic.hfytgp.cn
http://bronchiectasis.hfytgp.cn
http://burnish.hfytgp.cn
http://alguazil.hfytgp.cn
http://barothermohygrogram.hfytgp.cn
http://catchment.hfytgp.cn
http://cedarn.hfytgp.cn
http://argol.hfytgp.cn
http://battlesome.hfytgp.cn
http://boyhood.hfytgp.cn
http://anemosis.hfytgp.cn
http://aristocrat.hfytgp.cn
http://barometrograph.hfytgp.cn
http://chalicosis.hfytgp.cn
http://cab.hfytgp.cn
http://bulwark.hfytgp.cn
http://afternoon.hfytgp.cn
http://bennett.hfytgp.cn
http://ascetical.hfytgp.cn
http://celia.hfytgp.cn
http://bilbo.hfytgp.cn
http://checkwriter.hfytgp.cn
http://cadaverous.hfytgp.cn
http://bandung.hfytgp.cn
http://borak.hfytgp.cn
http://antiterrorism.hfytgp.cn
http://www.dtcms.com/a/260403.html

相关文章:

  • Java设计模式->责任链模式的介绍
  • Java 编程之备忘录模式
  • SQL学习笔记3
  • LeetCode--37.解数独
  • 使用 Nordic Connect SDK (NCS) 而不是标准 Zephyr 的优势是什么
  • AI+时代已至|AI人才到底该如何培育?
  • ubuntu部署woodpecker依赖gitea
  • 6月26日星期四今日早报简报微语报早读
  • [论文阅读]RaFe: Ranking Feedback Improves Query Rewriting for RAG
  • GraphQL注入 -- GPN CTF 2025 Real Christmas
  • 通过对 NIDS 自适应黑盒对抗性攻击披露漏洞
  • 攻防世界-MISC-4-2
  • 力扣网C语言编程题:搜索插入位置
  • Python 数据分析与可视化 Day 8 - Pandas 高级操作技巧
  • 表单数据收集实现分析
  • Python 中 `bytes` 与 `str` 的核心差异及注意事项
  • python中学物理实验模拟:斜面受力分析
  • IDEA + Spring Boot + javadoc 实例应用
  • Java底层原理:深入理解JVM性能调优与监控
  • 腾讯云产品都有哪些
  • 永磁无刷电机旋转原理
  • 大脑感官:视觉系统中将感观信息转换为神经信号
  • 苍穹外卖day3--公共字段填充+新增菜品
  • Python打卡:Day36
  • 《告别一换就崩:前端游戏物理引擎适配层设计哲学》
  • Redis-set集合
  • Altera PCI IP target设计分享
  • dockers virbox 安装
  • MySQL多表关系
  • 【已解决】Android Studio gradle遇到unresolved reference错误