На Visual Basic Sub Roma Dim R As String, N As Long, k As Integer, i As Integer R = InputBox ("Vvedite Rimskoe chislo") N = 0 : k = 0 i = 1 Do k = InStr$(R, i, "M") If k > 0 Then N = N + 1000 Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "CM") If k > 0 Then N = N - 100 Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "D") If k > 0 Then N = N + 500 Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "CD") If k > 0 Then N = N - 100 Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "C") If k > 0 Then If (Mid$(R, k+1, 1) <> "D") And (Mid$(R, k+1, 1) <> "M") Then N = N + 100 End If End If Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "XC") If k > 0 Then N = N - 10 Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "L") If k > 0 Then N = N + 50 Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "XL") If k > 0 Then N = N - 10 Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "X") If k > 0 Then If (Mid$(R, k+1, 1) <> "C") And (Mid$(R, k+1, 1) <> "L") Then N = N + 10 End If End If Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "IX") If k > 0 Then N = N - 1 Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "V") If k > 0 Then N = N + 5 Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "IV") If k > 0 Then N = N - 1 Loop While ((k > 0) And (i <= Len(R))) i = 1 Do k = InStr$(R, i, "I") If k > 0 Then If (Mid$(R, k+1, 1) <> "X") And (Mid$(R, k+1, 1) <> "V") Then N = N + 1 End If End If Loop While ((k > 0) And (i <= Len(R))) MsgBox (N) End Sub
Answers & Comments
Verified answer
На Visual BasicSub Roma
Dim R As String, N As Long, k As Integer, i As Integer
R = InputBox ("Vvedite Rimskoe chislo")
N = 0 : k = 0
i = 1
Do
k = InStr$(R, i, "M")
If k > 0 Then N = N + 1000
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "CM")
If k > 0 Then N = N - 100
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "D")
If k > 0 Then N = N + 500
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "CD")
If k > 0 Then N = N - 100
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "C")
If k > 0 Then
If (Mid$(R, k+1, 1) <> "D") And (Mid$(R, k+1, 1) <> "M") Then
N = N + 100
End If
End If
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "XC")
If k > 0 Then N = N - 10
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "L")
If k > 0 Then N = N + 50
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "XL")
If k > 0 Then N = N - 10
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "X")
If k > 0 Then
If (Mid$(R, k+1, 1) <> "C") And (Mid$(R, k+1, 1) <> "L") Then
N = N + 10
End If
End If
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "IX")
If k > 0 Then N = N - 1
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "V")
If k > 0 Then N = N + 5
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "IV")
If k > 0 Then N = N - 1
Loop While ((k > 0) And (i <= Len(R)))
i = 1
Do
k = InStr$(R, i, "I")
If k > 0 Then
If (Mid$(R, k+1, 1) <> "X") And (Mid$(R, k+1, 1) <> "V") Then
N = N + 1
End If
End If
Loop While ((k > 0) And (i <= Len(R)))
MsgBox (N)
End Sub