Last active
March 8, 2016 13:08
-
-
Save fa7ad/d0d653b9123d5776cba3 to your computer and use it in GitHub Desktop.
Area of Triangle - I tried to solve [this](https://algo.codemarshal.org/problems/556b5fc29c5e850300c49caf) using Heron's formula, but CodeMarshal won't accept it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <algorithm> | |
#include <iomanip> | |
void clearIO() | |
{ | |
int ch; | |
while ((ch = std::cin.get()) != std::cin.eof() && ch != '\n'); | |
} | |
int main(int argc, char* argv[]) | |
{ | |
int cn; | |
std::cin >> cn; | |
cn = abs(cn); | |
if (cn <= 100) { | |
double inps[cn][3]; | |
double areas[cn]; | |
clearIO(); | |
for (int i = 0; i < cn; i++) { | |
std::cin >> inps[i][0] >> inps[i][1] >> inps[i][2]; | |
clearIO(); | |
} | |
for (int d = 0; d < cn; d++) { | |
double a = inps[d][0], | |
b = inps[d][1], | |
c = inps[d][2]; | |
double s = (a+b+c)/2; | |
areas[d] = sqrt(s*(s-a)*(s-b)*(s-c)); | |
std::cout << "Case " << d + 1 << ": " << std::fixed << std::setprecision (10) << areas[d] << std::endl; | |
} | |
} | |
return 0; | |
} |
Mother of Gods... CodeMarshal accepted it 😆, needed the magical precision of TEN 😵
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Look at the oldest revision for my most recent attempt at "debugging" (I posted the most recent version first, sorry 😵 ).