(SPOJ) 8703 - Conta de água - Solução
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
void processa() throws NumberFormatException, IOException {
String line = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
line = br.readLine();
StringTokenizer tokenizer = new StringTokenizer(line);
int consumo = Integer.valueOf(tokenizer.nextToken());
int valor = 0;
int tmp;
if (consumo >= 101) {
tmp = consumo - 100;
for (int i = 0; i < tmp; i++) {
valor += 5;
}
consumo = 100;
}
if (consumo >= 31 && consumo <= 100) {
tmp = consumo - 30;
for (int i = 0; i < tmp; i++) {
valor += 2;
}
consumo = 30;
}
if (consumo >= 11 && consumo <= 30) {
tmp = consumo - 10;
valor = valor + tmp;
consumo = 10;
}
if (consumo <= 10) {
valor += 7;
}
System.out.println(valor);
return;
}
}
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
void processa() throws NumberFormatException, IOException {
String line = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
line = br.readLine();
StringTokenizer tokenizer = new StringTokenizer(line);
int consumo = Integer.valueOf(tokenizer.nextToken());
int valor = 0;
int tmp;
if (consumo >= 101) {
tmp = consumo - 100;
for (int i = 0; i < tmp; i++) {
valor += 5;
}
consumo = 100;
}
if (consumo >= 31 && consumo <= 100) {
tmp = consumo - 30;
for (int i = 0; i < tmp; i++) {
valor += 2;
}
consumo = 30;
}
if (consumo >= 11 && consumo <= 30) {
tmp = consumo - 10;
valor = valor + tmp;
consumo = 10;
}
if (consumo <= 10) {
valor += 7;
}
System.out.println(valor);
return;
}
}
Comments
Post a Comment