Sub Main() Dim str As String = "358 123 874 826 638" If TestDomino(str) Then Console.WriteLine("possible") Console.WriteLine(str) Else Console.WriteLine("impossible ") End If End Sub Function TestDomino(ByRef str As String) As Boolean Dim values() As String = str.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries) Dim ok As Boolean = TestDomino(values, 0, values.GetUpperBound(0)) If ok Then str = String.Join(" "c, values) End If Return ok End Function Function TestDomino(ByRef values() As String, ByVal startpos As Integer, ByVal endpos As Integer) As Boolean Dim tmp As String Dim ok As Boolean = CheckDomino(values) Dim i, j As Integer i = startpos While Not ok AndAlso i <= endpos j = i + 1 While Not ok AndAlso j <= endpos tmp = values(i) values(i) = values(j) values(j) = tmp ok = TestDomino(values, i + 1, endpos) If Not ok Then values(j) = values(i) values(i) = tmp j += 1 End If End While i += 1 End While Return ok End Function Function CheckDomino(ByRef values() As String) As Boolean Dim ok As Boolean = True Dim i As Integer = 0 While ok AndAlso i < values.Length - 1 Dim a As String = values(i).Substring(values(i).Length - 1) Dim b As String = values(i + 1).Substring(0, 1) ok a b i += 1 End While Return ok End Function
Function MonDeLaFonction(str As String) As Boolean Dim groups() As String = str.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries) Dim ok As Boolean = True Dim i As Integer = 0 While ok AndAlso i < groups.Length - 1 Dim a As String = groups(i).Substring(groups(i).Length - 1) Dim b As String = groups(i + 1).Substring(0, 1) ok a b i += 1 End While Return ok End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionch = "123 358 826 638 874" For i = 5 To Len(ch) Step 4 If Left(Mid(ch, i, 3), 1) <> Right(Mid(ch, i - 2, 1), 1) Then Exit For Next If i >= Len(ch) Then MsgBox "bon" Else MsgBox "mauvais"
tableau wagon = splite de la chaine "358 123 874 826 638" indice1 = 0 indice2 = 1 temporaire = vide réponse = vrai TANT QUE réponse = vrai et que indice 2 < que le nombre de cases de tableau wagon SI le dernier caractère du tableau wagon case indice1 n'est pas égale au premier caractère du tableau wagon case indice2 VRAI: réponse = non FAUX: temporaire = tableau wagon case indice1 tableau wagon case indice1 = tableau wagon case indice2 tableau wagon case indice2 = temporaire FIN DU SI incrémenter indice1 et indice2 RÉPÉTÉ SI réponse = vrai VRAI: afficher les cases du tableau wagon FAUX: afficher "impossible" FIN DU SI
ch = "123 358 826 638 874" For i = 5 To Len(ch) Step 4 If Mid(ch, i, 1) <> Mid(ch, i - 2, 1) Then Exit For Next If i >= Len(ch) Then MsgBox "bon" Else MsgBox "mauvais"