diff options
| author | Syndamia <kamen@syndamia.com> | 2023-10-19 19:40:08 +0300 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2023-10-19 19:40:08 +0300 |
| commit | fbbe586d25b1ebaf66fe2e92e1986bb5debf961d (patch) | |
| tree | 58f288b71fd5d1e046158b442438ea282285a619 /week02/exercise11.cpp | |
| parent | a597f37a109398549d8ab098a2d6de19a4a1b4b8 (diff) | |
| download | upp-2023-solutions-fbbe586d25b1ebaf66fe2e92e1986bb5debf961d.tar upp-2023-solutions-fbbe586d25b1ebaf66fe2e92e1986bb5debf961d.tar.gz upp-2023-solutions-fbbe586d25b1ebaf66fe2e92e1986bb5debf961d.zip | |
[w2] Added solutions
Diffstat (limited to 'week02/exercise11.cpp')
| -rw-r--r-- | week02/exercise11.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/week02/exercise11.cpp b/week02/exercise11.cpp new file mode 100644 index 0000000..7d1de63 --- /dev/null +++ b/week02/exercise11.cpp @@ -0,0 +1,21 @@ +#include <iostream> + +int main() { + // Много не съм ползвал константи в решенията, не защото няма смисъл да се прави, а така някои неща по-лесно се виждат + const int LIGHT_SPEED = 29; + + int timeSent, firstSatelliteCoord, firstSatelliteTimeRecv, secondSatelliteCoord, secondSatelliteTimeRecv; + std::cin >> timeSent >> firstSatelliteCoord >> firstSatelliteTimeRecv >> secondSatelliteCoord >> secondSatelliteTimeRecv; + + int distanceToFirst = (firstSatelliteTimeRecv - timeSent) / 2 * LIGHT_SPEED; + int distanceToSecond = (secondSatelliteTimeRecv - timeSent) / 2 * LIGHT_SPEED; + + // Повтарям логиката тука: имаме 4 възможни точни, първия сателит +- дистаниця и втория сателит +- дистанция + // Понеже данните не лъжат, трябва две от тези 4 възможности да съвпадат, и това проверяваме + // Допускаме че входа е валиден, така че това работи + if (firstSatelliteCoord + distanceToFirst == secondSatelliteCoord + distanceToSecond || + firstSatelliteCoord + distanceToFirst == secondSatelliteCoord - distanceToSecond) + std::cout << (firstSatelliteCoord + distanceToFirst) << std::endl; + else + std::cout << (firstSatelliteCoord - distanceToSecond) << std::endl; +} |
