← Real problems

sac22cc3jp2

easyimplementationStatement on DMOJ

CP Lang

3 lineschecks
// sac22cc3jp2: is the segment between two points parallel to the x-axis, the y-axis, or neither?
let (x1, y1, x2, y2) = read<(Int, Int, Int, Int)>()
print(if y1 == y2: "x-axis" elif x1 == x2: "y-axis" else: "neither")

Accepted C++

55 lines · 0.08 s on the judge
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...) 1412
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

void solve() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	if (y1 == y2) {
		cout << "x-axis" << endl;
	} else if (x1 ==x2) {
		cout << "y-axis" << endl;
	} else {
		cout << "neither" << endl;
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cin.exceptions(ios::failbit);
	int t = 1;
	// cin >> t;
	for (int _ = 1; _ <= t; _++) {
		dbg(_);
		// cout << "Case #" << _ << ": ";
		solve();
	}
}