From d09b1a288ae51fe2e141676948d225296f2f7d72 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 2 Nov 2023 15:00:22 +0200 Subject: [w3] Added solutions --- week03/exercise11.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 week03/exercise11.cpp (limited to 'week03/exercise11.cpp') diff --git a/week03/exercise11.cpp b/week03/exercise11.cpp new file mode 100644 index 0000000..c4bf464 --- /dev/null +++ b/week03/exercise11.cpp @@ -0,0 +1,29 @@ +#include +#include + +int parseSensor(int s) { return ((((s=(s>>1)&(~0xF617A100))<0x54)?s|0xF01:s&0xCBFF)>>2)-21; } + +int main() { + int rawValue; + std::cin >> rawValue; + + int temp = parseSensor(rawValue); + assert(-20 <= temp); + assert(temp <= 40); + + if (30 <= temp && temp <= 40) { + std::cout << "Hot" << std::endl; + } + else if (20 <= temp && temp <= 29) { + std::cout << "Warm" << std::endl; + } + else if (11 <= temp && temp <= 19) { + std::cout << "Temperate" << std::endl; + } + else if (0 <= temp && temp <= 10) { + std::cout << "Cold" << std::endl; + } + else if (-20 <= temp && temp <= -1) { + std::cout << "Freezing" << std::endl; + } +} -- cgit v1.2.3