1 条题解
-
0
核心逻辑
根据平面直角坐标系的象限划分规则判断:
- 第一象限:
x > 0 且 y > 0→ 输出1; - 第二象限:
x < 0 且 y > 0→ 输出2; - 第三象限:
x < 0 且 y < 0→ 输出3; - 第四象限:
x > 0 且 y < 0→ 输出4。
代码实现
C
#include <stdio.h> int main() { int x, y; scanf("%d %d", &x, &y); if (x > 0 && y > 0) { printf("1\n"); } else if (x < 0 && y > 0) { printf("2\n"); } else if (x < 0 && y < 0) { printf("3\n"); } else { // x>0且y<0 printf("4\n"); } return 0; }C++
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; if (x > 0 && y > 0) { cout << "1" << endl; } else if (x < 0 && y > 0) { cout << "2" << endl; } else if (x < 0 && y < 0) { cout << "3" << endl; } else { cout << "4" << endl; } return 0; }Python
x, y = map(int, input().split()) if x > 0 and y > 0: print(1) elif x < 0 and y > 0: print(2) elif x < 0 and y < 0: print(3) else: print(4) - 第一象限:
- 1
信息
- ID
- 24
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- 5
- 标签
- 递交数
- 54
- 已通过
- 23
- 上传者