class XpLevel {
public static int levelToExp(int level) {
return (int) Math.
floor(1000 * Math.
pow(level,
1.5)); }
public static int expToLevel(int exp) {
double level
= Math.
pow(exp
/ 1000.0,
2 / 3.0); int a
= (int) Math.
floor(level
); int b
= (int) Math.
ceil(level
); return levelToExp(b) > exp ? a : b;
}
public static void main
(String[] args
) { for (int i = 0; i <= 20; i++) {
int exp = levelToExp(i);
System.
out.
print("Para o level " + i
+ " precisamos de " + exp
+ " EXP. "); int provaReal = expToLevel(exp);
int antes = expToLevel(exp - 1);
int depois = expToLevel(exp + 1);
System.
out.
print((exp
- 1) + " EXP = Level " + antes
+ ". "); System.
out.
print(exp
+ " EXP = Level " + provaReal
+ ". "); System.
out.
print((exp
+ 1) + " EXP = Level " + depois
+ "."); }
}
}
Y2xhc3MgWHBMZXZlbCB7CgogICAgcHVibGljIHN0YXRpYyBpbnQgbGV2ZWxUb0V4cChpbnQgbGV2ZWwpIHsKICAgICAgICByZXR1cm4gKGludCkgTWF0aC5mbG9vcigxMDAwICogTWF0aC5wb3cobGV2ZWwsIDEuNSkpOwogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgaW50IGV4cFRvTGV2ZWwoaW50IGV4cCkgewogICAgICAgIGRvdWJsZSBsZXZlbCA9IE1hdGgucG93KGV4cCAvIDEwMDAuMCwgMiAvIDMuMCk7CiAgICAgICAgaW50IGEgPSAoaW50KSBNYXRoLmZsb29yKGxldmVsKTsKICAgICAgICBpbnQgYiA9IChpbnQpIE1hdGguY2VpbChsZXZlbCk7CiAgICAgICAgcmV0dXJuIGxldmVsVG9FeHAoYikgPiBleHAgPyBhIDogYjsKICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPD0gMjA7IGkrKykgewogICAgICAgICAgICBpbnQgZXhwID0gbGV2ZWxUb0V4cChpKTsKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludCgiUGFyYSBvIGxldmVsICIgKyBpICsgIiBwcmVjaXNhbW9zIGRlICIgKyBleHAgKyAiIEVYUC4gIik7CiAgICAgICAgICAgIGludCBwcm92YVJlYWwgPSBleHBUb0xldmVsKGV4cCk7CiAgICAgICAgICAgIGludCBhbnRlcyA9IGV4cFRvTGV2ZWwoZXhwIC0gMSk7CiAgICAgICAgICAgIGludCBkZXBvaXMgPSBleHBUb0xldmVsKGV4cCArIDEpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50KChleHAgLSAxKSArICIgRVhQID0gTGV2ZWwgIiArIGFudGVzICsgIi4gIik7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnQoZXhwICsgIiBFWFAgPSBMZXZlbCAiICsgcHJvdmFSZWFsICsgIi4gIik7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnQoKGV4cCArIDEpICsgIiBFWFAgPSBMZXZlbCAiICsgZGVwb2lzICsgIi4iKTsKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCk7CiAgICAgICAgfQogICAgfQp9