Skip to content

Instantly share code, notes, and snippets.

@fa7ad
Last active March 8, 2016 13:08
Show Gist options
  • Save fa7ad/d0d653b9123d5776cba3 to your computer and use it in GitHub Desktop.
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
#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;
}
@fa7ad
Copy link
Author

fa7ad commented Mar 5, 2016

Look at the oldest revision for my most recent attempt at "debugging" (I posted the most recent version first, sorry 😵 ).

@fa7ad
Copy link
Author

fa7ad commented Mar 7, 2016

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