Download presentation
Presentation is loading. Please wait.
1
פתרון תרגילים #9
2
דוגמה פשוטה #1 Module Module1 Sub Main() Dim x As String x = Console.ReadLine For i = 1 To x.Length() - 1 Step 2 Console.WriteLine(x(i)) Next Console.ReadKey() End Sub
3
וריאציה טובה... #1 Module Module1 Sub Main() Dim x As String Console.WriteLine("Please enter sentence: ") x = Console.ReadLine If (x.Length = 0) Then Console.Write("There nothing in the sentence.") ElseIf (x.Length = 1) Then Console.Write("There only one letter in the sentence.") Else For i = 1 To (x.Length() - 1) Step +2 Console.Write(x(i)) Next End If Console.ReadKey() End Sub End Module
4
דוגמה סנטדרטי #1 Module Module1 Sub Main() Dim word As String Dim m As Integer Dim x As Integer = 1 Console.WriteLine("please enter word") word = Console.ReadLine m = word.Length() - 1 While x <= m Console.Write(word(x)) x += 2 End While Console.ReadKey() End Sub End Module
5
דוגמה יותר מעניינת #1 Module Module1 Sub Main() Dim word, j As String Dim i, g As Integer word = Console.ReadLine j = "" For i = 0 To word.Length() - 1 g = g + 2 j = j + Mid(word, g, 1) Next Console.WriteLine(j) Console.ReadKey() End Sub End Module
6
איך שאני הייתי עושה #,32... Module Module1 Sub Main() Dim x As String Dim i As Integer = 0 x = Console.ReadLine Do Until (x(i) = " ") i += 1 Loop x = x.Remove(i, 1) Do Until (x(i) = " ") Console.Write(x(i)) i += 1 Loop End Sub End Module
7
וריאציה יותר פשוטה... ל#2,3 Module Module1 Sub Main() Dim x As String Dim i As Integer = 0 x = Console.ReadLine Do Until (x(i) = " ") i += 1 Loop i += 1 Do Until (x(i) = " ") Console.Write(x(i)) i += 1 Loop End Sub End Module
8
תשובה יפה... Module Module1 Sub Main() Dim x As String Dim i, counter, temp1, temp2 As Integer Console.WriteLine("Please enter sentence: ") x = Console.ReadLine For i = 0 To x.Length() - 1 If (x(i) = " ") Then counter += 1 If (counter = 1) Then temp1 = i ElseIf (counter = 2) Then temp2 = i End If Next If (x.Length = 0) Then Console.Write("There nothing in the sentence.") ElseIf (counter < 3) Then Console.Write("There no enough words in the sentence.") Else Console.WriteLine(Len(Mid(x, temp1 + 2, temp2 - temp1 - 1))) End If Console.ReadKey() End Sub End Module
9
ועוד אחד... Module Module1 Sub Main() Dim x As String Dim i, j As Integer x = Console.ReadLine() i = 0 j = 0 While x(i) <> " " i = i + 1 End While i = i + 1 While (x(i) <> " ") And (i <= x.Length) j = j + 1 i = i + 1 End While Console.WriteLine(j) Console.ReadKey() End Sub End Module
10
וריאציה מורכבת לפתרון שלי Module Module1 Sub Main() Dim word As String Dim i, ww As Integer word = Console.ReadLine For i = 0 To word.length() - 1 If word(i) = " " Then i += 1 While word(i) <> " " i += 1 ww = ww + 1 End While Exit For End If Next Console.WriteLine(ww) Console.ReadKey() End Sub End Module
11
#4 – הדרך הקלה... Module Module1 Sub Main() Dim x As String Dim y, z As Char Console.WriteLine("Please enter sentence, and two letters: ") x = Console.ReadLine y = Console.ReadLine z = Console.ReadLine x = x.Replace(y, z) Console.WriteLine(x) Console.ReadKey() End Sub End Module
12
אבל למה לעשות חיים קלים??? Module Module1 Sub Main() Dim x As String Dim i, j As Integer x = Console.ReadLine() j = 0 While x(i) <> " " And j <> 1 If x(i) <> " " Then x = x.Remove(i, 1) x = x.Insert(i, "Z") j = 1 End If i = i + 1 End While Console.WriteLine("the string is now is: " & x) Console.ReadKey() End Sub End Module
13
פתרון ל#5 Module Module1 Function Counter(ByVal word As String, ByVal key As Char) As Integer Dim i, x As Integer For i = 0 To word.Length - 1 If word(i) = key Then x = x + 1 End If Next Return x End Function Sub Main() Dim t, v As String t = Console.ReadLine v = Console.ReadLine Console.WriteLine(Counter(t, v)) Console.ReadKey() End Sub
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.