yxc solution
判断条件里面if(x==0)等价于if(!x)
#include <iostream>
using namespace std;
int main()
{
double x, y;
cin >> x >> y;
if (x > 0 && y > 0) cout << "Q1" << endl;
else if (x < 0 && y > 0) cout << "Q2" << endl;
else if (x < 0 && y < 0) cout << "Q3" << endl;
else if (x > 0 && y < 0) cout << "Q4" << endl;
else
{
if (!x && !y) cout << "Origem" << endl;
else if (!y) cout << "Eixo X" << endl;
else cout << "Eixo Y" << endl;
}
return 0;
}
my solution
#include<iostream>
using namespace std;
int main(){
double x, y;
cin>>x>>y;
if(x>0 && y>0) cout<<"Q1"<<endl;
if(x>0 && y<0) cout<<"Q4"<<endl;
if(x<0 && y>0) cout<<"Q2"<<endl;
if(x<0 && y<0) cout<<"Q3"<<endl;
if(x==0 && y!=0) cout<<"Eixo Y"<<endl;
if(y==0 && x!=0) cout<<"Eixo X"<<endl;
if(x==0 && y==0) cout<<"Origem"<<endl;
return 0;
}