Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- /**
- * Created by Vitor Hugo on 13/08/2016.
- */
- public class Cesar {
- public static void main(String[] args) {
- int casos;
- List<String> toCript = new ArrayList<>();
- List<Integer> junpCript = new ArrayList<>();
- List<String> cript = new ArrayList<>();
- Scanner sc = new Scanner(System.in);
- casos = Integer.parseInt(sc.nextLine());
- while (casos != 0) {
- sc.reset();
- toCript.add(sc.nextLine());
- junpCript.add(Integer.valueOf(sc.nextLine()));
- casos--;
- }
- for (String frase : toCript) {
- int junp = junpCript.get(toCript.indexOf(frase));
- char[] currentFrase = frase.toCharArray();
- for (int i = 0; i < currentFrase.length; i++) {
- int valueAscii = currentFrase[i];
- if(valueAscii - junp >=65){
- currentFrase[i] = (char) (valueAscii - junp);
- }else{
- valueAscii = (valueAscii - 65);
- valueAscii =Math.abs(valueAscii -junp);
- valueAscii = 90 - valueAscii +1 ;
- currentFrase[i] = (char) valueAscii;
- }
- }
- cript.add(String.valueOf(currentFrase));
- }
- for (String frase: cript) {
- System.out.println(frase);
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment