2021.4.11 字节跳动实习笔试题---情报解密

2021.4.11 字节跳动实习笔试题—情报解密

题目内容

题目内容:
给你一个字符串,该字符串中有数字,字母(字母只有大写字母)以及一些其他的字符(例如:%,.等),如果首字母为字母或者数字的话,就将整个字符串中的字母和字符都移动首字母对应的ASCll值的,就比如"A123"就解密为"B234",而如果首字母的为"%",则就将"%"看做是"A"即可,如果是其他的字符,则不需要解密。

import java.util.Scanner;

public class qingbao {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();

        char[] res = str.toCharArray();
        int temp;
        if('A' <= res[0] && res[0] <= 'Z'){
            temp = res[0] - 'A' + 1;
        }
        else if('0' <= res[0] && '9' >= res[0]){
            temp = res[0] - '0';
        }else{
            temp = 1;
        }

        for(int i = 0; i < res.length; i++){
            if('A' <= res[i] && res[i] <= 'Z'){
                res[i] = (char)((res[i] + temp - 'A') % 26 + 'A');
            }
            else if('0' <= res[i] && res[i] <= '9'){
                res[i] = (char)((res[i] + temp - '0') % 10 + '0');
            }
            else{
                continue;
            }
        }

        System.out.println(new String(res));

    }
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值