forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolygonarea.cpp
41 lines (34 loc) · 830 Bytes
/
polygonarea.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
double zipper(vector<pair<double, double>>& v) {
double total = 0;
int n = v.size();
for(int i = 0, j = 1; i < n; i++, j = (j+1) % n) {
total += v[i].first * v[j].second;
total -= v[i].second * v[j].first;
}
return total / 2;
}
int main() {
int n;
while(cin >> n && n != 0) {
vector<pair<double, double>> v;
for(int i = 0; i < n; i++) {
pair<double, double> p;
cin >> p.first >> p.second;
v.push_back(p);
}
double ans = zipper(v);
cout << fixed;
cout.precision(1);
if(ans < 0) {
cout << "CW ";
}
else {
cout << "CCW ";
}
cout << abs(ans) << endl;
}
}