<?
$start = microtime(true);
$handle = @fopen("input.txt", "r");
$products = array();
$properties = array ();
if ($handle) {
$i=0;
while (($buffer = fgets($handle, 4096)) !== false) {
if ($i==0){
$count_products = trim($buffer);
}
if ($i>0 and $i<$count_products+1){
$arrayString = explode(' ',trim($buffer));
$arr = array();
foreach ($arrayString as $string){
$keyValArr= explode('=', $string);
$arr[$keyValArr[0]]=$keyValArr[1];
}
array_push($products, $arr);
}
if ($i==$count_products+1){
$count_properties = trim($buffer);
}
if ($i>$count_products+1){
//array_push($properties, explode(" ", trim($buffer)));
$arrayString = explode(' ',trim($buffer));
$arr = array();
foreach ($arrayString as $string){
$keyValArr= explode('=', $string);
$arr[$keyValArr[0]]=$keyValArr[1];
}
array_push($properties, $arr);
}
$i=$i+1;
}
if (!feof($handle)) {
echo "Ошибка: fgets() неожиданно потерпел неудачу\r\n";
}
fclose($handle);
}
//echo 'Время выполнения скрипта: '.(microtime(true) - $start).' сек.';
$response="";
foreach ($properties as $propertyString=>$arrayInProperty){
$numberProperty = count ($arrayInProperty);
// echo json_encode($arrayInProperty).'<br \>';
$numberProduct = 0;
foreach ($products as $productString=>$arrayInProduct){
$string="";
$index = 0;
foreach ($arrayInProperty as $property=>$value){
if(array_key_exists($property, $arrayInProduct)){
if (trim($arrayInProduct[$property])==$value){
$string = $string.$property.' = '. $arrayInProduct[$property]."<br \ >";
$index = $index+1;
}
else {
break;
}
}else {
// echo '/ not'.'<br \>';
break;
}
}
if ($numberProperty == $index){
$numberProduct = $numberProduct+1;
}
// echo $string;
// echo '<br \>';
}
$response = $response.$numberProduct.PHP_EOL;
}
$fp = fopen("output.txt", "w+");
fwrite($fp,$response);
//echo json_encode($arrayInProperty).'<br \>';
//echo json_encode($properties);
echo 'Время выполнения скрипта: '.(microtime(true) - $start).' сек.';
?>
if(array_key_exists($property, $arrayInProduct)){ //Если существует свойство у продукта
if (trim($arrayInProduct[$property])==$value){ // если данное свойство равно свойству продукта.
$string = $string.$property.' = '. $arrayInProduct[$property]."<br \ >";
$index = $index+1;
}
else {
break;
}
}else {
// echo '/ not'.'<br \>';
break;
}
[
'width=5' => [0, 3],
'ht=3' => [0, 3],
'len=10' => [0],
'name=circ' => [1, 2],
'rad=5' => [1, 2].
'name=sqr' => [3]
]
array_intersect([0, 3], [0, 3]) = [0, 3]
[1, 2]
[3]
array_intersect([0, 3], [0]) = [0]