You are on page 1of 8

CADENA INVERTIDA NUM 1 Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.

E ventArgs) Handles Button1.Click Dim cad, cad1 As String Dim tam As Integer cad = TextBox1.Text tam = Len(cad) For i = 1 To tam cad1 = Mid(cad, i, 1) + cad1 Next TextBox2.Text = cad1 End Sub End Class --------------NUM2 eliminacion de la primera cadena Module Module1 Sub Main() Dim a, b, cadCom, nCad As String Dim tamA, tamB, c, i, ini As Integer i = 0 Console.WriteLine("Ingrese Cadena 1") a = Console.ReadLine() tamA = Len(a) Console.WriteLine("Ingrese Cadena 2") b = Console.ReadLine() tamB = Len(b) For c = 0 To tamA - tamB cadCom = a.Substring(c, tamB) If cadCom = b Then i = 1 nCad = a.Replace(b, "") End If Next Console.WriteLine(nCad) If i = 0 Then Console.WriteLine("No se Encontro la Cadena") End If Console.ReadLine() End Sub End Module --------------------NUM3 PSub Main() Dim a, b, z As Integer Dim car, cad As String Console.WriteLine("Ingrese Caracter: ") car = Console.ReadLine() Console.WriteLine("Ingrese Cadena: ") cad = Console.ReadLine() a = 1 b = 0 z = Len(cad) While ((Mid(cad, a, 1) <> car) And (b <> z)) b = b + 1 a = a + 1

End While If b = z Then Console.WriteLine("El caracter '" & car & "' no se encuentra en la c adena") Else Console.WriteLine("Hay " & b & " Caracteres antes del caracter '" & car & "'") End If Console.ReadLine() End Sub End Module -----------------------NUM4 ELIMINAR LOS ESPACIOS EN BLANCO Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button1.Click Dim cad1, cad As String Dim tam As Integer cad = TextBox1.Text tam = Len(cad) For i = 1 To tam If Mid(cad, i, 1) <> " " Then TextBox2.Text &= Mid(cad, i) i = tam End If Next End Sub End Class -------NUMM5 INGRESAR UNA CADENA A LA PRIMERA CON UN NUMERO Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button1.Click Dim cad1, cad2, cadt As String Dim tam1, tam2, n, a, b As Integer cad1 = TextBox1.Text cad2 = TextBox2.Text n = TextBox3.Text tam1 = Len(cad1) tam2 = Len(cad2) For i = 1 To tam1 If n = i Then TextBox4.Text &= cadt & cad2 & Mid(cad1, i) i = tam1 End If cadt = cadt + Mid(cad1, i, 1) Next End Sub End Class -------------------------NUM 6 BUSCAR LA SEGUNDA CADENA EN LA PRIMERA Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button1.Click Dim pais, busqueda As String

pais = TextBox1.Text busqueda = TextBox2.Text For i = 1 To 12 If Mid(pais, i, 2) = busqueda Then TextBox3.Text &= "Si se encontro la cadena" & " " & i Else TextBox3.Text = "No se encuentra la cadena" End If Next End Sub End Class --------------NUM 7 CONTAR PALABRAS SIN LIMITARSE CON LOS ESPACIOS EN BLANCO Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button1.Click Dim cad As String Dim tam, a, b As Integer cad = TextBox1.Text tam = Len(cad) For i = 1 To tam If Mid(cad, i, 1) <> " " Then a = a + 1 ElseIf a > 0 Then b = b + 1 a = 0 End If Next If Mid(cad, tam, 1) <> " " Then TextBox2.Text = "Existe " & b + 1 & " Palabras" End If If Mid(cad, tam, 1) = " " Then TextBox2.Text = "Existe " & b & " Palabras" End If End Sub End Class ---------------------* NUM 8 REEMPLAZAR UN * EN UNA CADENA Module Module1 Sub Main() Dim cadena, nuCar, viCar, remp As String Dim tamCad, tamVi, c As Integer Console.WriteLine("Ingrese cadena") cadena = Console.ReadLine Console.WriteLine("Ingrese caracter viejo") viCar = Console.ReadLine tamVi = Len(viCar) Console.WriteLine("Ingrese caracter nuevo") nuCar = Console.ReadLine tamCad = Len(cadena) For c = 0 To tamCad - tamVi remp = cadena.Substring(c, tamVi) If remp = viCar Then cadena = cadena.Replace(viCar, nuCar) End If Next Console.WriteLine(cadena) Console.ReadLine()

End Sub End Module --------------------------------NUM9 Module _01ESTRUCT Structure Punto Dim abscisa As Single Dim ordenada As Single End Structure Structure Ciudad Dim situacion As Punto Dim nombre As String End Structure Sub main() Dim aux As Ciudad Dim lugar(10) As Ciudad Dim euc1, euc2, x, x1, x2, y1, y2, y As Single Dim nom As String Dim can, j, b, w, i As Integer b = 0 Console.WriteLine("Cantida de ciudades entre 5 y 10") can = Console.ReadLine For j = 1 To can Console.WriteLine(vbCrLf & "Ciudad " & j) Console.Write("Nombre: ") lugar(j).nombre = Console.ReadLine Console.WriteLine("SITUACION") Console.Write("eje x ") lugar(j).situacion.abscisa = Console.ReadLine Console.Write("eje y ") lugar(j).situacion.ordenada = Console.ReadLine Next Console.WriteLine("_________________________") For i = 1 To can x = lugar(i).situacion.abscisa y = lugar(i).situacion.ordenada Console.WriteLine(lugar(i).nombre & " (" & x & "," & y & ")") Next Console.WriteLine(vbCrLf & "Ingrese nombre de la ciudad ") nom = Console.ReadLine For j = 1 To can If nom = lugar(j).nombre Then w = j b = 1 j = can x = lugar(j).situacion.abscisa y = lugar(j).situacion.ordenada End If Next If b = 0 Then Console.WriteLine("Ciudad no encontrada") Else aux.nombre = lugar(1).nombre aux.situacion.abscisa = lugar(1).situacion.abscisa aux.situacion.ordenada = lugar(1).situacion.ordenada lugar(1).nombre = lugar(w).nombre lugar(1).situacion.abscisa = x lugar(1).situacion.ordenada = y lugar(w).nombre = aux.nombre

lugar(w).situacion.abscisa = aux.situacion.abscisa lugar(w).situacion.ordenada = aux.situacion.ordenada For i = 1 To can - 1 For j = 2 To can - 1 x1 = lugar(j).situacion.abscisa y1 = lugar(j).situacion.ordenada euc1 = ((x - x1) ^ 2 + (y - y1) ^ 2) ^ (1 / 2) x2 = lugar(j + 1).situacion.abscisa y2 = lugar(j + 1).situacion.ordenada euc2 = ((x - x2) ^ 2 + (y - y2) ^ 2) ^ (1 / 2) If euc1 > euc2 Then aux.nombre = lugar(j).nombre aux.situacion.abscisa = lugar(j).situacion.abscisa aux.situacion.ordenada = lugar(j).situacion.ordenada lugar(j).nombre = lugar(j + 1).nombre lugar(j).situacion.abscisa = lugar(j + 1).situacion.absc isa lugar(1).situacion.ordenada = lugar(j + 1).situacion.ord enada lugar(j + 1).nombre = aux.nombre lugar(j + 1).situacion.abscisa = aux.situacion.abscisa lugar(j + 1).situacion.ordenada = aux.situacion.ordenada End If Next Next Console.WriteLine("___________________________________ ") Console.WriteLine("Distancia desde " & lugar(1).nombre & vbCrLf) Console.WriteLine("----------------------------------- ") For i = 2 To can x1 = lugar(i).situacion.abscisa y1 = lugar(i).situacion.ordenada euc1 = ((x - x1) ^ 2 + (y - y1) ^ 2) ^ (1 / 2) Console.WriteLine(lugar(i).nombre & " (" & x1 & "," & y1 & ") -- " & euc1) Next End If Console.ReadKey() End Sub End Module -----------------------------------Module _02estruct Structure DVD Dim codigo As Integer Dim titulo As String Dim ao As Integer End Structure Sub main() Dim V(1000) As DVD Dim aux As DVD Dim j, i, x, tn, can, b, cod As Integer Dim m, n As Char Dim may, a, s, tit As String b = 0 Console.Write("Cantidad de DVDs a almacenar: ") can = Console.ReadLine For j = 1 To can Console.WriteLine(vbCrLf & "DVD " & j) Console.WriteLine("Codigo: " & j)

V(j).codigo = j Console.Write("Titulo: ") V(j).titulo = Console.ReadLine Console.Write("Ao: ") V(j).ao = Console.ReadLine Next For i = 1 To can - 1 For j = 1 To can - 1 a = V(j).titulo s = V(j + 1).titulo If Len(a) >= Len(s) Then tn = Len(s) may = a Else tn = Len(a) may = s End If For x = 1 To tn m = Mid(a, x, 1) n = Mid(s, x, 1) If m <> n Then If m >= n Then may = a Else may = s End If x = tn + 1 End If Next If may = a Then aux.codigo = V(j).codigo aux.titulo = V(j).titulo aux.ao = V(j).ao V(j).codigo = V(j + 1).codigo V(j).titulo = V(j + 1).titulo V(j).ao = V(j + 1).ao V(j + 1).codigo = aux.codigo V(j + 1).titulo = aux.titulo V(j + 1).ao = aux.ao End If Next Next Console.WriteLine(vbCrLf & "Ordenando" & vbCrLf) For j = 1 To can Console.WriteLine(V(j).titulo & " " & V(j).codigo & " " & V(j).ao) Next Console.WriteLine(vbCrLf & "Ingrese Titulo a Buscar") tit = Console.ReadLine For j = 1 To can If tit = V(j).titulo Then Console.WriteLine("Codigo de DVD: " & V(j).codigo) b = 1 j = can End If Next If b = 0 Then Console.WriteLine("-1") End If Console.WriteLine(vbCrLf & "Ingrese codigo para cambiar titulo")

cod = Console.ReadLine b = 0 For j = 1 To can If cod = V(j).codigo Then Console.WriteLine("Titulo original: " & V(j).titulo) Console.WriteLine("Ingrese nuevo titulo") V(j).titulo = Console.ReadLine b = 1 j = can End If Next If b = 0 Then Console.WriteLine("codigo no en contrado") End If For i = 1 To can - 1 For j = 1 To can - 1 a = V(j).titulo s = V(j + 1).titulo If Len(a) >= Len(s) Then tn = Len(s) may = a Else tn = Len(a) may = s End If For x = 1 To tn m = Mid(a, x, 1) n = Mid(s, x, 1) If m <> n Then If m >= n Then may = a Else may = s End If x = tn + 1 End If Next If may = a Then aux.codigo = V(j).codigo aux.titulo = V(j).titulo aux.ao = V(j).ao V(j).codigo = V(j + 1).codigo V(j).titulo = V(j + 1).titulo V(j).ao = V(j + 1).ao V(j + 1).codigo = aux.codigo V(j + 1).titulo = aux.titulo V(j + 1).ao = aux.ao End If Next Next Console.WriteLine(vbCrLf & "Ordenando" & vbCrLf) For j = 1 To can Console.WriteLine(V(j).titulo & " " & V(j).codigo & " " & V(j).ao) Next Console.ReadKey() End Sub End Module

You might also like