破译密码
题解
讨论
查看他人的提交
题号:NC204449
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
牛牛收到了一个任务,任务要求牛牛破译一个密码。牛牛将被给予两个字符串s1和s2,均由四个小写字母构成。需要破译的密码为从s1变换到s2最少需要的变换次数。
变换的方式是这样:每次变换可以选择当前字符串中的一个位置,然后剩下的三个位置的字符从左到右分别加上2,3,5,若是超出'z',则重新从'a'开始,例如:对于字符串"abcd",我们选择'c'的位置进行变换,则变换之后的字符串为"ceci";对于字符串"qyzr",我们选择'r'位置进行变换,则变换之后的字符串为"sber"。
示例1
输入
复制
"aaaa","ccgk"
"aaaa","ccgk"
返回值
复制
2
2
说明
第一次变换选择第一个'a',变成"acdf",第二次变换选择第二个'c',变成"ccgk",故答案为2
备注:
s1,s2均由四个小写字母组成
破译密码
返回全部题目
列表加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 返回最终的答案 * @param s1 string 表示初始的字符串 * @param s2 string 表示目标的字符串 * @return int */ public int solve (String s1, String s2) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 返回最终的答案 * @param s1 string 表示初始的字符串 * @param s2 string 表示目标的字符串 * @return int */ int solve(string s1, string s2) { // write code here } };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 返回最终的答案 # @param s1 string 表示初始的字符串 # @param s2 string 表示目标的字符串 # @return int # class Solution: def solve(self , s1 , s2 ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 返回最终的答案 * @param s1 string 表示初始的字符串 * @param s2 string 表示目标的字符串 * @return int */ public int solve (string s1, string s2) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 返回最终的答案 * @param s1 string 表示初始的字符串 * @param s2 string 表示目标的字符串 * @return int */ function solve( s1 , s2 ) { // write code here } module.exports = { solve : solve };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 返回最终的答案 # @param s1 string 表示初始的字符串 # @param s2 string 表示目标的字符串 # @return int # class Solution: def solve(self , s1 , s2 ): # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 返回最终的答案 * @param s1 string 表示初始的字符串 * @param s2 string 表示目标的字符串 * @return int */ func solve( s1 string , s2 string ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 返回最终的答案 * @param s1 string 表示初始的字符串 * @param s2 string 表示目标的字符串 * @return int */ int solve(char* s1, char* s2 ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 返回最终的答案 # @param s1 string 表示初始的字符串 # @param s2 string 表示目标的字符串 # @return int # class Solution def solve(s1, s2) # write code here end end
"aaaa","ccgk"
2