|
|
back to boardWA17 Who can help me? C++ : #include "iostream" using namespace std; int main() { int n; double X1, Y1, X2, Y2; cin >> n >> X1 >> Y1 >> X2 >> Y2; double x1 = X1, y1 = Y1, x2 = X2, y2 = Y2, x3, y3, ans = 0; for(int i = 1; i <= n - 2; i++) { cin >> x3 >> y3; ans += x2 * (y3 - y1) + x3 * (y1 - y2) + x1 * (y2 - y3); x1 = x2; y1 = y2; x2 = x3; y2 = y3; } ans += x2 * (Y1 - y1) + X1 * (y1 - y2) + x1 * (y2 - Y1); x1 = x3; y1 = y3; x2 = X1; y2 = Y1; ans += x2 * (Y2 - y1) + X2 * (y1 - y2) + x1 * (y2 - Y2); ans > 0 ? cout << "ccw" : cout << "cw"; return 0; } Pascal: {$R-} Var X, Y: Array[1..200002] Of Extended; i, n: LongInt; Ans: Extended; Function AL(Const x1, y1, x2, y2, x3, y3: Extended): Extended; Begin AL := x2 * (y3 - y1) + x3 * (y1 - y2) + x1 * (y2 - y3); End; { AL } Begin ReadLn(n); For i := 1 To n Do ReadLn(X[i], Y[i]); X[n + 1] := X[1]; Y[n + 1] := Y[1]; X[n + 2] := X[2]; Y[n + 2] := Y[2]; ans := 0; For i := 1 To n Do ans := ans + AL(X[i], Y[i], X[i + 1], Y[i + 1], X[i + 2], Y[i + 2]); If ans < 0 Then Write('cw') Else Write('ccw'); End. Edited by author 25.08.2010 18:34 |
|
|