-
Lenguaje
Pascal
-
Descripción
Pide una frase y determina si es palíndrome
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
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
program program_palindrome;
uses crt;
var frase : string;
var primero, ultimo, tamano : integer;
var palindrome : boolean;
var tecla : char;
begin
primero := 1;
palindrome := true;
write ('Ingrese una frase: ');
readln (frase);
tamano := length (frase);
ultimo := tamano;
while palindrome and (primero <= tamano) and (ultimo >= 1) do
begin
while (primero <= tamano) and not (upcase (frase[primero]) in ['A'..'Z']) do
inc (primero);
while (ultimo >= 1) and not (upcase (frase[ultimo]) in ['A'..'Z']) do
dec (ultimo);
if (primero <= tamano) and (ultimo >= 1) and (upcase (frase[primero]) = upcase (frase[ultimo])) then
begin
inc (primero);
dec (ultimo);
end
else
palindrome := false;
end;
write (#10#13'La frase '#39, frase, #39' ');
if palindrome then
write (' s'#161)
else
write ('no');
writeln (' es pal'#161'ndrome.'#10#13);
write ('Presione una tecla para terminar . . . ');
tecla := readkey;
end.
uses crt;
var frase : string;
var primero, ultimo, tamano : integer;
var palindrome : boolean;
var tecla : char;
begin
primero := 1;
palindrome := true;
write ('Ingrese una frase: ');
readln (frase);
tamano := length (frase);
ultimo := tamano;
while palindrome and (primero <= tamano) and (ultimo >= 1) do
begin
while (primero <= tamano) and not (upcase (frase[primero]) in ['A'..'Z']) do
inc (primero);
while (ultimo >= 1) and not (upcase (frase[ultimo]) in ['A'..'Z']) do
dec (ultimo);
if (primero <= tamano) and (ultimo >= 1) and (upcase (frase[primero]) = upcase (frase[ultimo])) then
begin
inc (primero);
dec (ultimo);
end
else
palindrome := false;
end;
write (#10#13'La frase '#39, frase, #39' ');
if palindrome then
write (' s'#161)
else
write ('no');
writeln (' es pal'#161'ndrome.'#10#13);
write ('Presione una tecla para terminar . . . ');
tecla := readkey;
end.