题解 | #字符串加密#

字符串加密

https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别

        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            String res = in.nextLine();
		  //存放新顺序的26个字母
            char [] arr  = new char[26];
		  //检验字母重复
            int [] check = new int [26];
            int j = 0;
		  //将key去重放入 arr中
            for (int i = 0 ; i < str.length(); i++) {
                char c = str.charAt(i);
                if (check[c - 'a'] == 0) {
                    arr[j] = c;
                    j++;
                }
                check[c - 'a'] = 1;
            }
		//将剩余的字母按顺序放入arr中
            for(int i = 0 ; i <26 ; i++){
                if(check[i]==0){
                    arr[j] = (char)('a'+i);
                    j++;
                }
            }
            StringBuffer resBuffer = new StringBuffer();
		  //解密
            for(int i = 0 ; i <res.length();i++){
              char c =   arr[res.charAt(i)-'a'];
              resBuffer.append(c);

            }
            System.out.println(resBuffer);
        }
    }
}

全部评论

相关推荐

06-12 17:46
门头沟学院 Java
运营你豪哥:来说重点: ​1.项目前置,时间倒序。​​ 2.​项目描述强化结果与量化效果(STAR原则里的R)。​​ ​3.个人技能精炼,明确掌握程度,突出核心。​​ ​4.增加强有力开头的个人总结部分。​​ 5.​优化教育背景(成绩排名)、合并奖项与活动。​​
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务