Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
practica 9 ejercicio 3
program HelloWorld; {-----------------------------------------------------------------------------------------------------------------------} {----------------------------------------------------------------- CONST - Define las constantes para usar en tiempo de compilacion} const FIN = 'fin'; {-----------------------------------------------------------------------------------------------------------------------} {-----------------------------------------------------------------------------------------------------------------------} {----------------------------------------------------------------- TYPE - Define los tipos creados por el usuario para usar en tiempo de compilacion} type //----------TIPOS----------// Tnombre = string[15]; Tlugar = record nombre : Tnombre; pais : Tnombre; end; //----------LISTAS----------// Tlista = ^nodo; nodo = record datos : Tlugar; sig : Tlista; end; Tlista2 = ^nodo2; nodo2 = record datos : Tnombre; sig : Tlista2; end; {-----------------------------------------------------------------------------------------------------------------------} {-----------------------------------------------------------------------------------------------------------------------} {----------------------------------------------------------------- VARIABLES GLOBALES - Define variables que se podran usar por todos los modulos de ser necesarias} //var {-----------------------------------------------------------------------------------------------------------------------} {-----------------------------------------------------------------------------------------------------------------------} {----------------------------------------------------------------- LEER LUGAR ...} procedure leerLugar(var e : Tlugar); begin readln(e.nombre); if e.nombre <> FIN then readln(e.pais); end; {----------------------------------------------------------------- AGREGAR ELEMENTO ...} procedure agregarElemento(var l : Tlista; e : Tlugar); var nue : Tlista; begin new(nue); nue^.datos:= e; nue^.sig := l; l := nue; end; {----------------------------------------------------------------- CARGAR LISTA ...} procedure cargarLista(var l: Tlista); var n : Tlugar; begin l:=nil; leerLugar(n); while (n.nombre <> FIN) do begin agregarElemento(l,n); leerLugar(n); end end; {-----------------------------------------------------------------------------------------------------------------------} {----------------------------------------------------------------- IMPRIMIR LISTA ...} procedure imprimirLista( l: Tlista); var i : integer; begin i := 1; while l <> nil do begin writeln(i,'_ nombre: ',l^.datos.nombre,'. pais: ',l^.datos.pais,'.'); l:= l^.sig; i:= i + 1; end; writeln('-----------------------------------------------------------------'); end; {-----------------------------------------------------------------------------------------------------------------------} {----------------------------------------------------------------- BUSCAR PAIS...} function buscarPais(l : Tlista;pais:Tnombre):boolean; begin while (l <> nil)and(l^.datos.pais <> pais)do l := l^.sig; if l <> nil then begin buscarPais := true; end else buscarPais := false; end; {----------------------------------------------------------------- AGREGAR AL FINAL...} procedure agregarAlFinal(var l: Tlista2; e : Tnombre); var aux,nue : Tlista2; begin new (nue); nue^.datos := e; nue^.sig:= nil; aux := l; if l <> nil then begin while aux^.sig <> nil do aux := aux^.sig; aux^.sig := nue; end else l:=nue; end; {----------------------------------------------------------------- IMPRIMIR LISTA 2...} procedure imprimirLista2( l: Tlista2); begin writeln('------------------------------LISTA2-----------------------------------'); while l <> nil do begin writeln(l^.datos,'.'); l:= l^.sig; end; writeln('-----------------------------------------------------------------'); end; {----------------------------------------------------------------- INFORMAR ...} procedure informar(long,cant:integer;p,p2 : Tnombre;l2 : Tlista2); begin writeln('la longitud total de la lista es ',long,'.'); writeln('la cantidad de veces que aparece el pais ',p,' es ',cant); writeln('lista de lugares turisticos de ',p2); imprimirLista2(l2); end; {----------------------------------------------------------------- RECORRER LISTA ...} procedure recorrerLista(l: Tlista); var longitud : integer; // representa la longitud total de la lista pais : Tnombre; // pais a ingresar para ver cuantas veces aparece cant : integer; // representa la cantidad de veces que aparece el pais leido l2 : Tlista2; pais2 : Tnombre; begin // inicializacion a longitud := 0; // inicializacion b cant := 0; readln(pais); // inicializacion C y D readln(pais2); while not buscarPais(l,pais2) do readln(pais2); l2 := nil; // recorrido while l <> nil do begin // ejercicioA longitud := longitud + 1; // ejercicioB if pais = l^.datos.pais then cant := cant + 1; // ejercicio C y D if pais2 = l^.datos.pais then agregarAlFinal(l2,l^.datos.nombre); l := l^.sig; end; informar(longitud,cant,pais,pais2,l2); end; {-----------------------------------------------------------------------------------------------------------------------} {-----------------------------------------------------------------------------------------------------------------------} {----------------------------------------------------------------- LIBERAR LISTA ...} procedure liberarLista(var l: Tlista); var aux : Tlista; begin while l <> nil do begin aux:=l^.sig; dispose(l); l := aux; end; end; {-----------------------------------------------------------------------------------------------------------------------} { se ingresa : nombre del lugar nombre del pais hasta ingresar fin como nombre del lugar... } {-----------------------------------------------------------------------------------------------------------------------} {----------------------------------------------------------------- PROGRAMA PRINCIPAL} var l : Tlista; begin cargarLista(l); imprimirLista(l); recorrerLista(l); liberarLista(l); end. {-----------------------------------------------------------------------------------------------------------------------} { 3. * Dada una lista de lugares turísticos identificados por nombre y país, definir una estructura de datos para almacenarlos y escribir un programa que implemente los siguientes módulos: a) Calcular la longitud de la lista. b) Calcular la cantidad de veces que aparece un país dado (un país puede aparecer más de una vez, ya que puede haber diferentes lugares turísticos). c) Dado un país, si existe, generar una nueva lista con los nombres de sus lugares turísticos. d) Agregar al final de la lista creada en c) un nuevo lugar turístico. }
run
|
edit
|
history
|
help
0
0, pi, pi/4
Localisation ND
practica 2 ejercicio 9
ruteo
Ipis unazad ulancana lista
Prodavnica
звёздное небо и подсчёт кратных звёзд
practica 11 ejercicio 5
Huong11a2@
practica 1 ejercicio 1