use std::fmt::{Display, Formatter, Result};
use std::process::exit;

struct Coefficient(usize, f64);

impl Display for Coefficient {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        let i = self.0;
        let c = self.1;

        if c == 0. {
            return Ok(());
        }

        write!(
            f,
            " {} {}e({})",
            if c < 0. {
                "-"
            } else if f.alternate() {
                " "
            } else {
                "+"
            },
            if (c.abs() - 1.).abs() < f64::EPSILON {
                "".to_string()
            } else {
                c.abs().to_string() + "*"
            },
            i + 1
        )
    }
}

fn usage() {
    println!("Usage: display-linear-combination a1 [a2 a3 ...]");
}

fn linear_combination(coefficients: &[f64]) -> String {
    let mut string = String::new();

    let mut iter = coefficients.iter().enumerate();