题解 | #字符串加解密#

字符串加解密

https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a

import java.util.*;  
  
public class Main {  
    public static void main(String[] args) {  
        String inttab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";  
        String outtab = "bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA1234567890";  
        String s1, s2;  
        Scanner scanner = new Scanner(System.in);  
        // System.out.print("请输入两个字符串:");  
        // System.out.print("第一个字符串:");  
        s1 = scanner.nextLine();  
        // System.out.print("第二个字符串:");  
        s2 = scanner.nextLine();  
        scanner.close();  
          
        for (int i = 0; i < s1.length(); i++) {  
            char c = s1.charAt(i);  
            int index = inttab.lastIndexOf(c);  
            s1 = s1.substring(0, i) + outtab.charAt(index) + s1.substring(i + 1);  
        }  
          
        for (int i = 0; i < s2.length(); i++) {  
            char c = s2.charAt(i);  
            int index = outtab.lastIndexOf(c);  
            s2 = s2.substring(0, i) + inttab.charAt(index) + s2.substring(i + 1);  
        }  
          
        System.out.println(s1);  
        System.out.println(s2);  
    }  
}

全部评论

相关推荐

11-02 09:49
已编辑
货拉拉_测试(实习员工)
热爱生活的仰泳鲈鱼求你们别卷了:没事楼主,有反转查看图片
点赞 评论 收藏
分享
爱看电影的杨桃allin春招:我感觉你在炫耀
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务