Skip to content

Instantly share code, notes, and snippets.

@icub3d
Created December 5, 2025 19:43
Show Gist options
  • Select an option

  • Save icub3d/df137c09757817e257107f61e5d95b49 to your computer and use it in GitHub Desktop.

Select an option

Save icub3d/df137c09757817e257107f61e5d95b49 to your computer and use it in GitHub Desktop.
Kattis temperature
use std::io::{Read, stdin};
fn main() {
let mut s = String::new();
stdin().read_to_string(&mut s).unwrap();
let (x, y) = s.trim().split_once(' ').unwrap();
let (x, y) = (x.parse::<f32>().unwrap(), y.parse::<f32>().unwrap());
// n = n*y + x
// 0 = yn - n + x
// n = x / (1-y)
let d = 1. - y;
let n = x / d;
if d.abs() < 1e-6 {
if x.abs() < 1e-6 {
// 0/0
println!("ALL GOOD");
} else {
// x/0
println!("IMPOSSIBLE");
}
} else if n.fract().abs() < 1e-6 {
println!("{}", n.round() as i32);
} else {
println!("{:.9}", n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment