Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Olympiad2016;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class t {
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- while (true) {
- String inputStart = console.nextLine();
- if (inputStart.equals("START") || inputStart.equals("start")) {
- break;
- }
- }
- int messageCount = 0;
- ArrayList<String> output = new ArrayList<>();
- StringBuilder encryptedMessage = new StringBuilder();
- while (true) {
- String input = console.nextLine();
- if (input.equals("END") || input.equals("end")) {
- break;
- }
- if (input.equals("")) {
- continue;
- }
- messageCount++;
- for (char ch : input.toCharArray()) {
- // For the digits 0 -> 1
- if (ch >= 48 && ch <= 57) {
- encryptedMessage.append(ch);
- // For upperCase letters A -> M
- } else if (ch >= 65 && ch <= 77) {
- encryptedMessage.append((char) (ch + 13));
- // For lowerCase letters a -> m
- } else if (ch >= 97 && ch <= 109) {
- encryptedMessage.append((char) (ch + 13));
- // For upperCase letters N -> Z
- } else if (ch >= 78 && ch <= 90) {
- encryptedMessage.append((char) (ch - 13));
- // For lowerCase letters n -> a
- } else if (ch >= 110 && ch <= 122) {
- encryptedMessage.append((char) (ch - 13));
- // For the special characters
- } else if (ch == 32) {
- encryptedMessage.append((char) 43);
- } else if (ch == 44) {
- encryptedMessage.append((char) 37);
- } else if (ch == 46) {
- encryptedMessage.append((char) 38);
- } else if (ch == 63) {
- encryptedMessage.append((char) 35);
- } else if (ch == 33) {
- encryptedMessage.append((char) 36);
- } else if (ch == 43) {
- encryptedMessage.append((char) 32);
- } else if (ch == 37) {
- encryptedMessage.append((char) 44);
- } else if (ch == 38) {
- encryptedMessage.append((char) 46);
- } else if (ch == 35) {
- encryptedMessage.append((char) 63);
- } else if (ch == 36) {
- encryptedMessage.append((char) 33);
- }
- }
- output.add(encryptedMessage.reverse().toString());
- //clear the stringBuilder for the next message
- encryptedMessage.setLength(0);
- }
- if (messageCount == 0) {
- System.out.println("No messages sent.");
- } else {
- System.out.println("Total number of messages: " + messageCount);
- }
- for (String string : output) {
- System.out.println(string);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement