Revisão | 6cdd7bbb98b9ccafd5a32a77e8fc90cc89647046 (tree) |
---|---|
Hora | 2021-12-07 18:15:33 |
Autor | SecT |
Commiter | SecT |
Task 2021 04 B CPP PASS
@@ -1445,7 +1445,7 @@ | ||
1445 | 1445 | { |
1446 | 1446 | if( board->get(i, 0) == -1 && board->get(i, 1) == -1 && board->get(i, 2) == -1 && board->get(i, 3) == -1 && board->get(i, 4) == -1 ) |
1447 | 1447 | { |
1448 | - return true; | |
1448 | + return true; | |
1449 | 1449 | } |
1450 | 1450 | } |
1451 | 1451 |
@@ -1453,7 +1453,7 @@ | ||
1453 | 1453 | { |
1454 | 1454 | if( board->get(0, i) == -1 && board->get(1, i) == -1 && board->get(2, i) == -1 && board->get(3, i) == -1 && board->get(4, i) == -1 ) |
1455 | 1455 | { |
1456 | - return true; | |
1456 | + return true; | |
1457 | 1457 | } |
1458 | 1458 | } |
1459 | 1459 |
@@ -1465,12 +1465,12 @@ | ||
1465 | 1465 | int res = 0; |
1466 | 1466 | |
1467 | 1467 | for(int i =0; i<5; i++){ |
1468 | - | |
1468 | + | |
1469 | 1469 | for(int j=0; j<5;j++) |
1470 | 1470 | { |
1471 | 1471 | if(board->get(i,j) != -1) |
1472 | 1472 | { |
1473 | - res+= board->get(i,j); | |
1473 | + res+= board->get(i,j); | |
1474 | 1474 | } |
1475 | 1475 | } |
1476 | 1476 |
@@ -1484,6 +1484,9 @@ | ||
1484 | 1484 | { |
1485 | 1485 | int result = 0; |
1486 | 1486 | |
1487 | + boards.clear(); | |
1488 | + randomlySelectedNumbers.clear(); | |
1489 | + | |
1487 | 1490 | parseRandomlySelectedNumbers(inputData[0]); |
1488 | 1491 | |
1489 | 1492 | parseBoards(inputData); |
@@ -1499,17 +1502,12 @@ | ||
1499 | 1502 | { |
1500 | 1503 | result = calculateScore( (*board), (*selectedNum) ); |
1501 | 1504 | |
1502 | - boards.clear(); | |
1503 | - randomlySelectedNumbers.clear(); | |
1504 | - | |
1505 | 1505 | return result; |
1506 | 1506 | } |
1507 | 1507 | } |
1508 | 1508 | |
1509 | 1509 | } |
1510 | 1510 | |
1511 | - boards.clear(); | |
1512 | - randomlySelectedNumbers.clear(); | |
1513 | 1511 | |
1514 | 1512 | return result; |
1515 | 1513 | } |
@@ -1518,5 +1516,43 @@ | ||
1518 | 1516 | { |
1519 | 1517 | int result = 0; |
1520 | 1518 | |
1519 | + boards.clear(); | |
1520 | + randomlySelectedNumbers.clear(); | |
1521 | + | |
1522 | + std::vector<int> boardsThatWon; | |
1523 | + | |
1524 | + parseRandomlySelectedNumbers(inputData[0]); | |
1525 | + | |
1526 | + parseBoards(inputData); | |
1527 | + | |
1528 | + | |
1529 | + for(auto selectedNum = randomlySelectedNumbers.begin(); selectedNum != randomlySelectedNumbers.end(); selectedNum++) | |
1530 | + { | |
1531 | + int currentBoardId = 0; | |
1532 | + for(auto board = boards.begin(); board != boards.end(); board++) | |
1533 | + { | |
1534 | + markNumAsSelectedOnBoard( (*board), (*selectedNum) ); | |
1535 | + | |
1536 | + if( checkIfWin( (*board) ) ) | |
1537 | + { | |
1538 | + if(std::find(boardsThatWon.begin(), boardsThatWon.end(), currentBoardId) == boardsThatWon.end()) | |
1539 | + { | |
1540 | + boardsThatWon.push_back(currentBoardId); | |
1541 | + | |
1542 | + if(boardsThatWon.size() == boards.size()){ | |
1543 | + result = calculateScore( (*board), (*selectedNum) ); | |
1544 | + return result; | |
1545 | + | |
1546 | + } | |
1547 | + } | |
1548 | + | |
1549 | + } | |
1550 | + currentBoardId++; | |
1551 | + } | |
1552 | + | |
1553 | + } | |
1554 | + | |
1555 | + | |
1556 | + | |
1521 | 1557 | return result; |
1522 | 1558 | } |
\ No newline at end of file |
@@ -164,10 +164,10 @@ | ||
164 | 164 | testValuesForInputFile[2] = "15 91 51 68 49"; |
165 | 165 | |
166 | 166 | testValuesForExamples[0] = 4512; |
167 | - testValuesForExamples[1] = 0; | |
167 | + testValuesForExamples[1] = 1924; | |
168 | 168 | |
169 | 169 | testValuesForTask[0] = 16674; |
170 | - testValuesForTask[1] = 0; | |
170 | + testValuesForTask[1] = 7075; | |
171 | 171 | |
172 | 172 | } |
173 | 173 |