寝癖頭の解法

学習中の覚え書きを投稿、更新していきます。

Aizu Online Judge in C++ #Volume0 - 0079 : Area of Polygon

Aizu Online Judge(AOJ)の過去問から、その提出コードの解答例です。

・問題 "Area of Polygon"
https://onlinejudge.u-aizu.ac.jp/problems/0079
・凸 n 角形の面積
僕が作成、提出したコードは、以下のとおりです。

・Aizu Online Judge in C++ #Volume0 - 0079 : Area of Polygon
/*
Aizu Online Judge in C++ #Volume0 - 0079 : Area of Polygon
 https://onlinejudge.u-aizu.ac.jp/problems/0079
 提出コードの解答例
 https://neguse-atama.hatenablog.com
*/
#include<bits/stdc++.h>
using namespace std;
int main(void){
    double x0,y0,x1,y1,x,y,s=0;
    char c;
    cin>>x0>>c>>y0;
    x1=x0,y1=y0;
    while(cin>>x>>c>>y){
        s+=x1*y-y1*x;
        x1=x;
        y1=y;
    }
    s+=x1*y0-y1*x0;
    cout<<(s<0 ? -s : s)/2<<endl;
    return 0;
}

設問の出典は、プログラミング問題のオンライン採点システム「Aizu Online Judge(AOJ)」です。
http://judge.u-aizu.ac.jp/onlinejudge/