After reading the solution and thoughts of July , I found that the last solution is quite succinct and beautiful. The major thought is that to make AB to BA (while A and B are sub-string of the original string), we can do the following : (A^B^)^ , while A^ means the reverse of A in character. Java implementation is provided below :
public class StringShift { public static void main(String[] args) { //m & n has no common factors assert "DEFGABC".equals(shift("ABCDEFG", 3, true)); assert "EFGABCD".equals(shift("ABCDEFG", 3, false)); //n is multiple of m assert "EFGHABCD".equals(shift("ABCDEFGH", 4, true)); assert "EFGHABCD".equals(shift("ABCDEFGH", 4, false)); //n and m shares a common factor assert "GHIABCDEF".equals(shift("ABCDEFGHI", 6, true)); assert "DEFGHIABC".equals(shift("ABCDEFGHI", 6, false)); } /** * AB ---> (A^B^)^ ---> BA * while A^ is the reverse order of A * */ private static Object shift(String origin, int m, boolean left) { //input check if ( origin == null) return null; int len = origin.length(); if (m == 0) return origin; m = left ? m : -m; // calulate the size of A int l = ( m + len ) % len; char[] arr = new char[len]; origin.getChars(0, len, arr, 0); reverse(arr , 0 , l); reverse(arr , l , len); reverse(arr , 0 , len); return new String(arr); } private static void reverse(char[] arr , int start , int end) { char temp; for ( int s = start , e = end - 1 ; s < e ; s ++, e -- ) { temp = arr[s]; arr[s] = arr[e]; arr[e] = temp; } }
相关推荐
因此,Quesion1的答案在于,对ICU患者进行营养风险评估是为了早期发现并干预可能出现的问题,以改善预后。Quesion2的答案则是,通常需要结合单一指标和综合指标,以确保评估的准确性和全面性,避免营养不足和过度...
rs("quesion")=trim(request("quesion")) rs("answer")=md5(trim(request("answer"))) rs("userzhenshiname")=trim(request("userzhenshiname")) rs("adddate")=now() rs("lastlogin")=now() rs("logins")=0 rs(...
PaddleX-YOLOv3
官方 HarmonyOS Sans字体资源。(来自官方公开资料)
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
软件开发C++重要培训资料分享13软件开发C++开发技术资料.zip
亲爱的嵌入式开发者们, 您是否在寻找一种强大且灵活的工具来创建高效的嵌入式应用程序?QT 是您的不二选择!我们为您精心准备了一份全面的 QT 嵌入式开发教程,帮助您从零开始,逐步掌握这门强大的技术。 为什么选择 QT 嵌入式开发? 跨平台支持:支持多种操作系统(如 Linux, Windows, macOS)和硬件平台(如 ARM, x86),实现一次编写,到处运行。 丰富的 UI 组件:内置大量高质量的 UI 组件,轻松创建美观且响应迅速的用户界面。 高性能:优化的图形渲染引擎和高效的内存管理,确保应用程序在资源受限的环境中也能流畅运行。 强大的生态系统:庞大的社区支持和丰富的第三方库,助您解决各种开发难题。 易于学习:C++ 和 QML 语言结合,既适合初学者也适合有经验的开发者。 本教程适合谁? 嵌入式开发新手:从未接触过 QT 的新手,希望快速入门。 专业工程师:希望提升技能,提高工作效率的专业人士。 学生:对嵌入式系统和 GUI 开发感兴趣的在校学生。 研究人员:需要进行嵌入式系统开发的研究
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
基于东方世界的微信小程序商城
该动漫社团项目“烟雨社”采用Html作为主要开发语言,融合了Python, JavaScript, CSS等辅助语言,整体源码包含80个文件,其中包括27个JPG图片、14个PNG图片、8个Python脚本、7个JavaScript脚本、5个XML配置文件、5个CSS样式表以及相关文档和配置文件。项目以清晰的结构和丰富的资源,为动漫爱好者提供了一个全面展示与互动的平台。
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
职业心理测试职业知识测试8个文件职业心理测试职业知识测试8个文件
54.基于matlab的模糊自适应PID控制器,PID参数的整定必须考虑到在不同时刻三个参数的作用及相互之间的关系。 在线实时模糊自整定PID算法的基础上,通过计算当前系统e和误差变化率ec,利用模糊规则进行模糊推理,查询模糊矩阵表进行参数调整。 程序已调通,可直接运行。
微信小程序商城,欢迎学习交流_微信
基于西门子S7-200PLC的自动灌溉系统组态王组态 带解释的梯形图程序,接线图原理图图纸,io分配,组态画面
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
STM32硬件液晶资料ILI9320(ID9320)
逆变器器设计资料 包含原理图设计详解 pcb布局详解 软件设计思路 原理图,pcb都有且是对应的方便学习设计
枝晶生长Comsol仿真模型。 锂枝晶生长过程的 枝晶生长Comsol仿真模型。 锂枝晶生长过程的枝晶形貌,温度场耦合,应力场,浓度场,电势场。 C++程序,基于元胞自动机法模拟枝晶生长,能实现任意角度(偏心正方算法),同时采用LBM考虑了对流作用对枝晶生长的影响
STM32软件学习资料NES资料STM32软件学习资料NES资料