Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Olympiad2016;
- import java.util.Scanner;
- public class t {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- while (true){
- String commandLine = sc.nextLine();
- if (commandLine.equals("start") || commandLine.equals("START")){
- break;
- }
- }
- int msgCounter = 0;
- StringBuilder decryptMsg = new StringBuilder();
- while (true) {
- String commandLine = sc.nextLine();
- if (commandLine.equals("end")|| commandLine.equals("END")) {
- break;
- }
- if (commandLine.equals("")) {
- continue;
- }
- msgCounter++;
- for (int index = commandLine.length() - 1; index >= 0; index--) {
- char currentSymbol = commandLine.charAt(index);
- boolean isFromAtoMLower = commandLine.charAt(index) >= 'a' && commandLine.charAt(index) <= 'm';
- boolean isFromAtoMUpper = commandLine.charAt(index) >= 'A' && commandLine.charAt(index) <= 'M';
- boolean isFromNtoZLower = commandLine.charAt(index) >= 'n' && commandLine.charAt(index) <= 'z';
- boolean isFromNtoZUpper = commandLine.charAt(index) >= 'N' && commandLine.charAt(index) <= 'Z';
- boolean isDigit = commandLine.charAt(index) >= '0' && commandLine.charAt(index) <= '9';
- if (isFromAtoMUpper || isFromAtoMLower) {
- decryptMsg.append((char) (commandLine.charAt(index) + 13));
- } else if (isFromNtoZUpper || isFromNtoZLower) {
- decryptMsg.append((char) (commandLine.charAt(index) - 13));
- } else if (isDigit) {
- decryptMsg.append(commandLine.charAt(index));
- } else {
- switch (currentSymbol) {
- case '+':
- decryptMsg.append(' ');
- break;
- case '%':
- decryptMsg.append(',');
- break;
- case '&':
- decryptMsg.append('.');
- break;
- case '#':
- decryptMsg.append('?');
- break;
- case '$':
- decryptMsg.append('!');
- break;
- }
- }
- }
- }
- if (msgCounter == 0){
- System.out.println("No messages sent.");
- }else {
- System.out.printf("Total number of messages: %d\n",msgCounter);
- System.out.println(decryptMsg.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement