plduhoux
2/21/2018 - 12:40 AM

rounders

int rounders(int value) {
    int res = value;
    while (!onezero(value)) {
        int i = 0; 
        int v = value;
        while (v % 10 == 0) {i++;v/=10;}
        if (v % 10 < 5) {
            value -= (v % 10) * Math.pow(10, i);
        } else {
            value += (10 - v % 10) * Math.pow(10, i);
        }
    }
    return value;
}
boolean onezero(int v) {
    int nbnz = 0;
    while (v != 0) {
        if (v % 10 != 0) nbnz++;
        v /= 10;
    }
    return nbnz == 1;
}