Что нового

Как посчитать повторяющиеся цифр в массивах

sasha1304

Новичок
Сообщения
41
Репутация
0
всем привет. есть вот такие массивы
Код:
Dim $bilet1[30] = [17,39,42,55,70,7,11,24,69,89,5,29,44,73,81,1,14,26,37,46,3,20,56,66,71,10,32,50,74,88]
Dim $bilet2[30] = [29,46,60,71,83,9,19,36,50,74,8,24,32,45,54,23,35,52,68,78,12,27,47,51,80,6,48,69,75,89]
Dim $bilet3[30] = [3,46,68,70,80,4,12,27,52,77,19,32,55,66,84,18,21,31,44,62,7,48,69,78,85,16,28,37,57,75]
Dim $bilet4[30] = [16,20,37,58,84,18,43,66,77,82,4,27,51,62,78,2,28,59,67,90,10,25,36,53,70,1,12,39,48,87]
Dim $bilet5[30] = [47,56,66,72,81,6,38,49,63,88,4,10,28,55,74,29,31,43,57,85,3,19,23,36,62,5,16,40,53,70]
Dim $bilet6[30] = [27,38,48,50,82,12,45,52,73,86,4,29,32,64,76,25,33,43,57,78,16,59,61,79,84,5,18,23,46,85]
Dim $bilet7[30] = [14,30,47,67,81,11,29,56,70,80,9,33,42,52,64,32,43,58,62,78,7,12,25,55,88,5,16,24,79,89]
Dim $bilet8[30] = [6,11,23,38,84,8,24,35,43,79,18,41,58,62,86,1,30,54,69,83,10,27,45,59,75,19,28,47,68,76]
Dim $bilet9[30] = [23,42,66,74,84,5,17,59,64,87,21,32,46,54,75,1,50,67,73,88,14,24,39,68,89,6,16,27,30,45]
Dim $bilet10[30] = [19,21,34,51,79,9,13,47,54,88,39,44,65,78,89,18,36,46,56,82,14,22,32,64,71,2,20,40,55,72]


нужно как то посчитать повторяющиеся в них цифры. например цифра 17 есть в массивах $bilet1 и $bilet9, значит нужно записать 17 повторяется 2 раза. как это сделать?
 

gunter123

Продвинутый
Сообщения
159
Репутация
69
Код:
Dim $bilet1[30] = [17,39,42,55,70,7,11,24,69,89,5,29,44,73,81,1,14,26,37,46,3,20,56,66,71,10,32,50,74,88]
Dim $bilet2[30] = [29,46,60,71,83,9,19,36,50,74,8,24,32,45,54,23,35,52,68,78,12,27,47,51,80,6,48,69,75,89]
Dim $bilet3[30] = [3,46,68,70,80,4,12,27,52,77,19,32,55,66,84,18,21,31,44,62,7,48,69,78,85,16,28,37,57,75]
Dim $bilet4[30] = [16,20,37,58,84,18,43,66,77,82,4,27,51,62,78,2,28,59,67,90,10,25,36,53,70,1,12,39,48,87]
Dim $bilet5[30] = [47,56,66,72,81,6,38,49,63,88,4,10,28,55,74,29,31,43,57,85,3,19,23,36,62,5,16,40,53,70]
Dim $bilet6[30] = [27,38,48,50,82,12,45,52,73,86,4,29,32,64,76,25,33,43,57,78,16,59,61,79,84,5,18,23,46,85]
Dim $bilet7[30] = [14,30,47,67,81,11,29,56,70,80,9,33,42,52,64,32,43,58,62,78,7,12,25,55,88,5,16,24,79,89]
Dim $bilet8[30] = [6,11,23,38,84,8,24,35,43,79,18,41,58,62,86,1,30,54,69,83,10,27,45,59,75,19,28,47,68,76]
Dim $bilet9[30] = [23,42,66,74,84,5,17,59,64,87,21,32,46,54,75,1,50,67,73,88,14,24,39,68,89,6,16,27,30,45]
Dim $bilet10[30] = [19,21,34,51,79,9,13,47,54,88,39,44,65,78,89,18,36,46,56,82,14,22,32,64,71,2,20,40,55,72]

Dim $allBilet[10] = [$bilet1, $bilet2, $bilet3, $bilet4, $bilet5, $bilet6, $bilet7, $bilet8, $bilet9, $bilet10]

_Find(17)

Func _Find($iNum)
   ConsoleWrite(" ### Ищем " & $iNum & " ### " & @CRLF)
   $iCount = 0
   For $i = 0 TO UBound($allBilet) -1
	  For $j = 0 To UBound($allBilet[$i]) -1
		 If ($allBilet[$i])[$j] = $iNum Then
			$iCount = $iCount +1
			ConsoleWrite(" --- Найдено в массиве #" & $i + 1 & @CRLF)
		 EndIf
	  Next
   Next
   ConsoleWrite(" ### Всего найдено: " & $iCount & @CRLF & @CRLF)
EndFunc
 
Автор
S

sasha1304

Новичок
Сообщения
41
Репутация
0
Спасибо, вы мне очень помогли. :IL_AutoIt_1:



gunter123 сказал(а):
Код:
Dim $bilet1[30] = [17,39,42,55,70,7,11,24,69,89,5,29,44,73,81,1,14,26,37,46,3,20,56,66,71,10,32,50,74,88]
Dim $bilet2[30] = [29,46,60,71,83,9,19,36,50,74,8,24,32,45,54,23,35,52,68,78,12,27,47,51,80,6,48,69,75,89]
Dim $bilet3[30] = [3,46,68,70,80,4,12,27,52,77,19,32,55,66,84,18,21,31,44,62,7,48,69,78,85,16,28,37,57,75]
Dim $bilet4[30] = [16,20,37,58,84,18,43,66,77,82,4,27,51,62,78,2,28,59,67,90,10,25,36,53,70,1,12,39,48,87]
Dim $bilet5[30] = [47,56,66,72,81,6,38,49,63,88,4,10,28,55,74,29,31,43,57,85,3,19,23,36,62,5,16,40,53,70]
Dim $bilet6[30] = [27,38,48,50,82,12,45,52,73,86,4,29,32,64,76,25,33,43,57,78,16,59,61,79,84,5,18,23,46,85]
Dim $bilet7[30] = [14,30,47,67,81,11,29,56,70,80,9,33,42,52,64,32,43,58,62,78,7,12,25,55,88,5,16,24,79,89]
Dim $bilet8[30] = [6,11,23,38,84,8,24,35,43,79,18,41,58,62,86,1,30,54,69,83,10,27,45,59,75,19,28,47,68,76]
Dim $bilet9[30] = [23,42,66,74,84,5,17,59,64,87,21,32,46,54,75,1,50,67,73,88,14,24,39,68,89,6,16,27,30,45]
Dim $bilet10[30] = [19,21,34,51,79,9,13,47,54,88,39,44,65,78,89,18,36,46,56,82,14,22,32,64,71,2,20,40,55,72]

Dim $allBilet[10] = [$bilet1, $bilet2, $bilet3, $bilet4, $bilet5, $bilet6, $bilet7, $bilet8, $bilet9, $bilet10]

_Find(17)

Func _Find($iNum)
   ConsoleWrite(" ### Ищем " & $iNum & " ### " & @CRLF)
   $iCount = 0
   For $i = 0 TO UBound($allBilet) -1
	  For $j = 0 To UBound($allBilet[$i]) -1
		 If ($allBilet[$i])[$j] = $iNum Then
			$iCount = $iCount +1
			ConsoleWrite(" --- Найдено в массиве #" & $i + 1 & @CRLF)
		 EndIf
	  Next
   Next
   ConsoleWrite(" ### Всего найдено: " & $iCount & @CRLF & @CRLF)
EndFunc
 

ra4o

AutoIT Гуру
Сообщения
1,165
Репутация
247
Вам нужно знать количество повторений всех цифр в массиве или какой-то конкретной одной ?
 

joiner

Модератор
Локальный модератор
Сообщения
3,557
Репутация
628
до кучи мой вариант поиска всех совпадений

Код:
Local $bilet1[30] = [17,39,42,55,70,7,11,24,69,89,5,29,44,73,81,1,14,26,37,46,3,20,56,66,71,10,32,50,74,88]
Local $bilet2[30] = [29,46,60,71,83,9,19,36,50,74,8,24,32,45,54,23,35,52,68,78,12,27,47,51,80,6,48,69,75,89]
Local $bilet3[30] = [3,46,68,70,80,4,12,27,52,77,19,32,55,66,84,18,21,31,44,62,7,48,69,78,85,16,28,37,57,75]
Local $bilet4[30] = [16,20,37,58,84,18,43,66,77,82,4,27,51,62,78,2,28,59,67,90,10,25,36,53,70,1,12,39,48,87]
Local $bilet5[30] = [47,56,66,72,81,6,38,49,63,88,4,10,28,55,74,29,31,43,57,85,3,19,23,36,62,5,16,40,53,70]
Local $bilet6[30] = [27,38,48,50,82,12,45,52,73,86,4,29,32,64,76,25,33,43,57,78,16,59,61,79,84,5,18,23,46,85]
Local $bilet7[30] = [14,30,47,67,81,11,29,56,70,80,9,33,42,52,64,32,43,58,62,78,7,12,25,55,88,5,16,24,79,89]
Local $bilet8[30] = [6,11,23,38,84,8,24,35,43,79,18,41,58,62,86,1,30,54,69,83,10,27,45,59,75,19,28,47,68,76]
Local $bilet9[30] = [23,42,66,74,84,5,17,59,64,87,21,32,46,54,75,1,50,67,73,88,14,24,39,68,89,6,16,27,30,45]
Local $bilet10[30] = [19,21,34,51,79,9,13,47,54,88,39,44,65,78,89,18,36,46,56,82,14,22,32,64,71,2,20,40,55,72]
Local $allBilet[10] = [$bilet1, $bilet2, $bilet3, $bilet4, $bilet5, $bilet6, $bilet7, $bilet8, $bilet9, $bilet10]

Local $oDict = ObjCreate('Scripting.Dictionary')
$oDict.CompareMode = 1
Local $tmpdata, $aData[4]
For $i = 0 To UBound($allBilet) - 1
	For $n = 0 To UBound($allBilet[$i]) - 1
		If $oDict.Exists(($allBilet[$i])[$n]) Then
			$tmpdata = $oDict.Item(($allBilet[$i])[$n])
			$tmpdata[1] += 1
			$tmpdata[2] &= '|' & ($i + 1)
			$tmpdata[3] &= '|' & $n
			$oDict.Item(($allBilet[$i])[$n]) = $tmpdata
		Else
			$aData[0] = ($allBilet[$i])[$n]
			$aData[1] = 1
			$aData[2] = ($i + 1)
			$aData[3] = $n
			$oDict.Add(($allBilet[$i])[$n], $aData)
		EndIf
	Next
Next

Local $AllKeys = $oDict.Keys()
For $i In $AllKeys
	$tmpdata = $oDict.Item($i)
	If $tmpdata[1] > 1 Then ConsoleWrite('Число: ' & $tmpdata[0] & ' Количество повторений: ' & $tmpdata[1] & ' Номера массивов: ' & $tmpdata[2] & ' Индексы в массивах: ' & $tmpdata[3]& @CRLF)
Next
 

Tempo

AutoIT Гуру
Сообщения
616
Репутация
205
И еще варианты
Код:
#include <Array.au3>
Local $aBilet1[30] = [17, 39, 42, 55, 70, 7, 11, 24, 69, 89, 5, 29, 44, 73, 81, 1, 14, 26, 37, 46, 3, 20, 56, 66, 71, 10, 32, 50, 74, 88]
Local $aBilet2[30] = [29, 46, 60, 71, 83, 9, 19, 36, 50, 74, 8, 24, 32, 45, 54, 23, 35, 52, 68, 78, 12, 27, 47, 51, 80, 6, 48, 69, 75, 89]
Local $aBilet3[30] = [3, 46, 68, 70, 80, 4, 12, 27, 52, 77, 19, 32, 55, 66, 84, 18, 21, 31, 44, 62, 7, 48, 69, 78, 85, 16, 28, 37, 57, 75]
Local $aBilet4[30] = [16, 20, 37, 58, 84, 18, 43, 66, 77, 82, 4, 27, 51, 62, 78, 2, 28, 59, 67, 90, 10, 25, 36, 53, 70, 1, 12, 39, 48, 87]
Local $aBilet5[30] = [47, 56, 66, 72, 81, 6, 38, 49, 63, 88, 4, 10, 28, 55, 74, 29, 31, 43, 57, 85, 3, 19, 23, 36, 62, 5, 16, 40, 53, 70]
Local $aBilet6[30] = [27, 38, 48, 50, 82, 12, 45, 52, 73, 86, 4, 29, 32, 64, 76, 25, 33, 43, 57, 78, 16, 59, 61, 79, 84, 5, 18, 23, 46, 85]
Local $aBilet7[30] = [14, 30, 47, 67, 81, 11, 29, 56, 70, 80, 9, 33, 42, 52, 64, 32, 43, 58, 62, 78, 7, 12, 25, 55, 88, 5, 16, 24, 79, 89]
Local $aBilet8[30] = [6, 11, 23, 38, 84, 8, 24, 35, 43, 79, 18, 41, 58, 62, 86, 1, 30, 54, 69, 83, 10, 27, 45, 59, 75, 19, 28, 47, 68, 76]
Local $aBilet9[30] = [23, 42, 66, 74, 84, 5, 17, 59, 64, 87, 21, 32, 46, 54, 75, 1, 50, 67, 73, 88, 14, 24, 39, 68, 89, 6, 16, 27, 30, 45]
Local $aBilet10[30] = [19, 21, 34, 51, 79, 9, 13, 47, 54, 88, 39, 44, 65, 78, 89, 18, 36, 46, 56, 82, 14, 22, 32, 64, 71, 2, 20, 40, 55, 72]

_ArrayConcatenate($aBilet1, $aBilet2)
_ArrayConcatenate($aBilet1, $aBilet3)
_ArrayConcatenate($aBilet1, $aBilet4)
_ArrayConcatenate($aBilet1, $aBilet5)
_ArrayConcatenate($aBilet1, $aBilet6)
_ArrayConcatenate($aBilet1, $aBilet7)
_ArrayConcatenate($aBilet1, $aBilet8)
_ArrayConcatenate($aBilet1, $aBilet9)
_ArrayConcatenate($aBilet1, $aBilet10)

_ArrayDisplay(_ArrayNumRepeats($aBilet1), "_ArrayNumRepeats", Default, $ARRAYDISPLAY_NOROW)
_ArrayDisplay(_ArrayNumRepeatsEx($aBilet1), "_ArrayNumRepeatsEx", Default, $ARRAYDISPLAY_NOROW)

Func _ArrayNumRepeats($aArray, $iStart = 0, $iEnd = 0, $iCase = 0, $iCompare = 0)
	If Not IsArray($aArray) Then Return SetError(1)
	Local $aRet, $j = 0
	If Not $iEnd Then $iEnd = UBound($aArray) - 1
	Local $aOut[$iEnd + 1][2]
	For $i = $iStart To $iEnd
		If $aArray[$i] Then
			$aRet = _ArrayFindAll($aArray, $aArray[$i], $iStart, $iEnd, $iCase, $iCompare)
			If Not @error Then
				$aOut[$j][0] = $aArray[$i]
				$aOut[$j][1] = UBound($aRet)
				For $i2 = 0 To $aOut[$j][1] - 1
					$aArray[$aRet[$i2]] = False
				Next
				$j += 1
			EndIf
		EndIf
	Next
	If Not $j Then Return SetError(2)
	ReDim $aOut[$j][2]
	Return $aOut
EndFunc   ;==>_ArrayNumRepeats

Func _ArrayNumRepeatsEx(ByRef Const $aArray)
	If Not IsArray($aArray) Then Return SetError(1)
	Local $oDict = ObjCreate("Scripting.Dictionary")
	If Not IsObj($oDict) Then Return SetError(2)
	$oDict.CompareMode = 1
	For $i = 0 To UBound($aArray) - 1
		$oDict.Item($aArray[$i]) += 1
	Next
	Local $aKeys = $oDict.Keys(), $iCount = UBound($aKeys)
	Local $aItems = $oDict.Items()
	Local $aOut[$iCount][2]
	For $i = 0 To $iCount - 1
		$aOut[$i][0] = $aKeys[$i]
		$aOut[$i][1] = $aItems[$i]
	Next
	If Not UBound($aOut) Then Return SetError(3)
	Return $aOut
EndFunc   ;==>_ArrayNumRepeatsEx
 

InnI

AutoIT Гуру
Сообщения
4,950
Репутация
1,445
Простой вариант для чисел
Код:
Local $bilet1[30]  = [17,39,42,55,70, 7,11,24,69,89, 5,29,44,73,81, 1,14,26,37,46, 3,20,56,66,71,10,32,50,74,88]
Local $bilet2[30]  = [29,46,60,71,83, 9,19,36,50,74, 8,24,32,45,54,23,35,52,68,78,12,27,47,51,80, 6,48,69,75,89]
Local $bilet3[30]  = [ 3,46,68,70,80, 4,12,27,52,77,19,32,55,66,84,18,21,31,44,62, 7,48,69,78,85,16,28,37,57,75]
Local $bilet4[30]  = [16,20,37,58,84,18,43,66,77,82, 4,27,51,62,78, 2,28,59,67,90,10,25,36,53,70, 1,12,39,48,87]
Local $bilet5[30]  = [47,56,66,72,81, 6,38,49,63,88, 4,10,28,55,74,29,31,43,57,85, 3,19,23,36,62, 5,16,40,53,70]
Local $bilet6[30]  = [27,38,48,50,82,12,45,52,73,86, 4,29,32,64,76,25,33,43,57,78,16,59,61,79,84, 5,18,23,46,85]
Local $bilet7[30]  = [14,30,47,67,81,11,29,56,70,80, 9,33,42,52,64,32,43,58,62,78, 7,12,25,55,88, 5,16,24,79,89]
Local $bilet8[30]  = [ 6,11,23,38,84, 8,24,35,43,79,18,41,58,62,86, 1,30,54,69,83,10,27,45,59,75,19,28,47,68,76]
Local $bilet9[30]  = [23,42,66,74,84, 5,17,59,64,87,21,32,46,54,75, 1,50,67,73,88,14,24,39,68,89, 6,16,27,30,45]
Local $bilet10[30] = [19,21,34,51,79, 9,13,47,54,88,39,44,65,78,89,18,36,46,56,82,14,22,32,64,71, 2,20,40,55,72]
Local $allBilet[10] = [$bilet1, $bilet2, $bilet3, $bilet4, $bilet5, $bilet6, $bilet7, $bilet8, $bilet9, $bilet10]

Local $aCount[100]
For $i = 0 To UBound($allBilet) - 1
  For $j = 0 To UBound($allBilet[$i]) - 1
    $aCount[($allBilet[$i])[$j]] += 1
  Next
Next

For $i = 0 To UBound($aCount) - 1
  If $aCount[$i] > 1 Then ConsoleWrite("Число " & $i & " повторяется " & $aCount[$i] & " раз(а)" & @CRLF)
Next
 
Верх