Aizu Online Judge(AOJ)の過去問から、その提出コードの解答例です。
・問題 "Parallel/Orthogonal"
https://onlinejudge.u-aizu.ac.jp/problems/CGL_2_A
・平行・垂直
僕が作成、提出したコードは、以下のとおりです。
Aizu Online Judge in C++ #CGL_2_A : Parallel/Orthogonal
/* Aizu Online Judge in C++ #CGL_2_A : Parallel/Orthogonal https://onlinejudge.u-aizu.ac.jp/problems/CGL_2_A 提出コードの解答例 https://neguse-atama.hatenablog.com */ #include<bits/stdc++.h> using namespace std; using C=complex<double>; int main(void){ int n; double ax,ay,bx,by,cx,cy,dx,dy; cin>>n; while(n--){ cin>>ax>>ay>>bx>>by>>cx>>cy>>dx>>dy; C com=C(bx-ax,by-ay)*C(dx-cx,cy-dy); if(com.imag()==0){ cout<<2<<endl; }else if(com.real()==0){ cout<<1<<endl; }else{ cout<<0<<endl; } } return 0; }
設問の出典は、プログラミング問題のオンライン採点システム「Aizu Online Judge(AOJ)」です。
http://judge.u-aizu.ac.jp/onlinejudge/