-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP102.java
113 lines (74 loc) · 2.32 KB
/
P102.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package aceptaelreto;
import java.util.*;
public class P102 {
static Scanner s;
static int calcularvocals(String d) {
int vocals = 0;
char v;
d = d.toLowerCase();
for (int i = 0; i < d.length(); i++) {
if (Character.isLetter(d.charAt(i))) {
v = d.charAt(i);
if (v == 'a' || v == 'e' || v == 'i' || v == 'o' || v == 'u') {
vocals++;
}
}
}
return vocals;
}
static String desencriptar(int d, String c) {
String decript = "";
int valor;
char r, nueva;
for (int i = 1; i < c.length(); i++) {
r = Character.toLowerCase(c.charAt(i));
if (Character.isLetter(r)) {
valor = r + d;
if (valor < 97) {
valor = 123 - (97 - valor);
} else if (valor > 122) {
valor = 96 + (valor - 122);
}
nueva = (char) valor;
if (Character.isUpperCase(c.charAt(i))) {
nueva = Character.toUpperCase(nueva);
}
decript += nueva;
} else {
decript += r;
}
}
return decript;
}
static int desplazamiento(char p) {
int der, izq;
p = Character.toLowerCase(p);
izq = (p < 'p')
? -((p - 'a') + (123 - 'p'))
: -(p - 'p');
der = (p > 'p')
? -(('z' - p) + ('p' - 96))
: ('p' - p);
return (Math.abs(izq) <= der) ? der : izq;
}
static boolean casDeProva() {
String c;
String decript;
int desp, dec;
c = s.nextLine();
desp = desplazamiento(c.charAt(0));
decript = desencriptar(desp, c);
if (decript.equals("FIN")) {
return false;
} else {
dec = calcularvocals(decript);
System.out.println(dec);
return true;
}
}
public static void main(String[] args) {
s = new Scanner(System.in);
while (casDeProva());
s.close();
}
}