#19680: 感覺能精簡些


siaoling_sky (siaoling)

學校 : 國立嘉義高級中學
編號 : 102641
來源 : [140.138.147.45]
最後登入時間 :
2023-11-16 00:00:52
d057. 11494 - Queen -- UVa11494 | From: [223.138.37.39] | 發表日期 : 2019-10-19 22:44

 

我用的是邏輯按順序判斷的方式,不知道能不能用算式解決呢? .w.

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
int x1,x2,y1,y2,a,b,ans ;

while(cin>>x1>>y1>>x2>>y2,x1>0 || y1>0 || x2>0 || y2>0)
{
a=fabs(x1-x2) ;
b=fabs(y1-y2) ;
if(a==0&&b==0)
ans=0 ;
else if (a==b)
ans=1 ;
else if(a==0)
ans=1 ;
else if(b==0)
ans=1 ;
else
ans=2 ;
cout<< ans << endl ;


}

 

 

return 0;
}

 
ZeroJudge Forum