Files
CodeTest/baekjoon/네_번째_점/solution_18510441.rs
2024-08-29 16:22:36 +09:00

102 lines
2.1 KiB
Rust

use std::io;
struct Position{
x: u32,
y: u32,
}
impl Position{
fn init(x: u32, y: u32) -> Position{
Position{
x,
y,
}
}
}
struct Rectangle{
xlines: [u32; 2],
ylines: [u32; 2],
counts: [u32; 4],
}
impl Rectangle{
fn init() -> Rectangle{
Rectangle{
xlines : [0;2],
ylines : [0;2],
counts : [0;4],
}
}
fn check(&mut self, pos: Position){
let (x, y) = (pos.x, pos.y);
if self.xlines[0] == 0{
self.xlines[0] = x;
self.counts[0] = 1;
}
else if self.xlines[0] == x{
self.counts[0] += 1;
}
else{
self.xlines[1] = x;
self.counts[1] += 1;
}
if self.ylines[0] == 0{
self.ylines[0] = y;
self.counts[2] = 1;
}
else if self.ylines[0] == y{
self.counts[2] += 1;
}
else{
self.ylines[1] = y;
self.counts[3] += 1;
}
}
fn find_last(&self) -> Position{
let (mut x, mut y) : (u32, u32) = (0, 0);
for i in 0..2{
if self.counts[i] == 1{
x = self.xlines[i];
break;
}
}
for i in 2..4{
if self.counts[i] == 1{
y = self.ylines[i - 2];
break;
}
}
Position::init(x, y)
}
}
fn main(){
let mut rect : Rectangle = Rectangle::init();
for _i in 0..3{
let mut line = String::new();
io::stdin().read_line(&mut line)
.expect("Failed to read line");
let mut line = line.trim().split(" ");
let x = line.next().expect("Not enough inputs")
.parse::<u32>().expect("Not an integer");
let y = line.next().expect("Not enough inputs")
.parse::<u32>().expect("Not an integer");
let pos = Position::init(x, y);
rect.check(pos);
}
let pos = rect.find_last();
println!("{} {}", pos.x, pos.y);
}