zoukankan      html  css  js  c++  java
  • Java实现 蓝桥杯 算法提高 文本加密

    算法提高 9-2 文本加密
    时间限制:1.0s 内存限制:256.0MB
    提交此题
    问题描述
      先编写函数EncryptChar,按照下述规则将给定的字符c转化(加密)为新的字符:“A"转化"B”,“B"转化为"C”,… …“Z"转化为"a”,“a"转化为"b”,… …, “z"转化为"A”,其它字符不加密。编写程序,加密给定字符串。
    样例输出
    与上面的样例输入对应的输出。
    例:

    数据规模和约定
      输入数据中每一个数的范围。
      例:50个字符以内无空格字符串。

    import java.util.Scanner;
    
    
    public class 文本加密 {
    	  public static String EncryptChar(String str){
    	        StringBuffer result = new StringBuffer();
    	        for ( int i = 0 ; i < str.length() ; i++){
    	            char a = str.charAt(i);
    	            if (a >= 'A' && a < 'Z'){
    	                a = (char) (a + 1);
    	                result.append(a);
    	            }else if (a == 'Z'){
    	                a = 'a';
    	                result.append(a);
    	            }else if (a >= 'a' && a < 'z'){
    	                a = (char) (a + 1);
    	                result.append(a);
    	            }else if(a == 'z'){
    	                a = 'A';
    	                result.append(a);
    	            }else{
    	                result.append(a);
    	            }
    	        }
    	        return result.toString();
    	    }
    
    	    public static void main(String[] args) {
    	        // TODO Auto-generated method stub
    	        Scanner in = new Scanner(System.in);
    	        String word = in.next();
    	        String result = EncryptChar(word);
    	        System.out.println(result);
    	        in.close();
    	    }
    
    
    }
    
    
  • 相关阅读:
    frp穿透.md
    6_模板与渲染.md
    4_多数据格式返回请求结果.md
    3_请求参数绑定与多数据格式处理.md
    5_中间件.md
    1_go_gin介绍.md
    2_Gin网络请求与路由处理.md
    14_文件.md
    firefox油猴脚本编写.md
    js 四舍五入
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13079347.html
Copyright © 2011-2022 走看看