POJ1298

本文提供了一段Java代码实现,用于解决PKU ACM 1298题,该题要求对输入的字符串进行特定的凯撒密码加密处理。程序使用了标准输入输出,并针对大写字母实现了移位加密逻辑。

 题目http://acm.pku.edu.cn/JudgeOnline/problem?id=1298

 

  1. import java.io.BufferedInputStream;
  2. import java.util.Scanner;
  3. public class Main {
  4.     String cipher;
  5.     char[] message;
  6.     char c;
  7.     public Main() {
  8.         Scanner scan = new Scanner(new BufferedInputStream(System.in));
  9.         while (!(cipher = scan.nextLine()).equals("ENDOFINPUT")) {
  10.             while (!(cipher = scan.nextLine()).equals("END")) {
  11.                 message = cipher.toCharArray();
  12.                 for (int i = 0; i < message.length; i++) {
  13.                     c = message[i];
  14.                     if (65 <= c && c <= 90) {
  15.                         c = (char) (65 + (c - 65 - 5 + 26) % 26);
  16.                         message[i] = c;
  17.                     }
  18.                 }
  19.                 System.out.println(String.valueOf(message));
  20.             }
  21.         }
  22.     }
  23.     public static void main(String[] args) {
  24.         new Main();
  25.     }
  26. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值