码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • L848字母位移


    //有一个由小写字母组成的字符串 s,和一个长度相同的整数数组 shifts。
    //我们将字母表中的下一个字母称为原字母的 移位 shift() (由于字母表是环绕的, 'z' 将会变成 'a')。
    //例如,shift('a') = 'b', shift('t') = 'u', 以及 shift('z') = 'a'。
    //对于每个 shifts[i] = x , 我们会将 s 中的前 i + 1 个字母移位 x 次。
    //返回 将所有这些移位都应用到 s 后最终得到的字符串 。
    //示例 1:
    //
    //输入:s = "abc", shifts = [3,5,9]
    //输出:"rpl"
    //解释:
    //我们以 "abc" 开始。
    //将 S 中的第 1 个字母移位 3 次后,我们得到 "dbc"。
    //再将 S 中的前 2 个字母移位 5 次后,我们得到 "igc"。
    //最后将 S 中的这 3 个字母移位 9 次后,我们得到答案 "rpl"。
    //
    //示例 2:
    //abcdefghijklmnopqrstuvwxyz
    //输入: s = "aaa", shifts = [1,2,3]
    //baa
    //dca
    //gfd
    //输出: "gfd"

    //提示:
    //    1 <= s.length <= 105
    //    s 由小写英文字母组成
    //    shifts.length == s.length
    //    0 <= shifts[i] <= 109

    1. public class L848字母位移 {
    2. public static void main(String[] args) {
    3. // TODO 自动生成的方法存根
    4. Scanner sc=new Scanner(System.in);
    5. String s=sc.next();
    6. int []shifts=new int[s.length()];
    7. for(int i=0;i<s.length();i++) {
    8. shifts[i]=sc.nextInt();
    9. }
    10. String stri=shiftingLetters(s,shifts);
    11. System.out.println(stri);
    12. }
    13. public static String shiftingLetters(String s, int[] shifts) {
    14. char []str=new char[s.length()];
    15. char []str1=new char[s.length()];
    16. int []num=new int[s.length()];
    17. String string="";
    18. int i=0;
    19. for(i=0;i<s.length();i++) {
    20. str[i]=s.charAt(i);
    21. num[i]=str[i];
    22. }
    23. i=0;
    24. while(i<s.length()) {
    25. for(int j=0;j<=i;j++) {
    26. num[j]+=shifts[i];
    27. if(num[j]>122) {
    28. num[j]-=26;
    29. }
    30. }
    31. i++;
    32. }
    33. for(i=0;i<s.length();i++) {
    34. str1[i]=(char) num[i];
    35. string+=str1[i];
    36. }
    37. return string;
    38. }
    39. }

  • 相关阅读:
    JavaScript速成课--面向对象程序设计
    【Linux精讲系列】——yum软件包管理
    Python 接口自动化测试详解
    npm ERR! Cannot read properties of null (reading ‘pickAlgorithm‘)
    C语言实现扫雷小游戏
    【LeetCode回溯算法#07】子集问题I+II,巩固解题模板并详解回溯算法中的去重问题
    小试牛刀-Telebot区块链游戏机器人
    基于微信小程序的电影院购票系统丨毕业设计源码
    Java基于API接口爬取商品数据
    [Codeforces] number theory (R1200) Part.9
  • 原文地址:https://blog.csdn.net/m0_64238242/article/details/127947641
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号