(SPOJ) 20671 - Senha da Tia - 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);
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
while (true) {
n = br.read();
if (n >= '0' && n <= '9') break;
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9') break;
}
return resp;
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int minCaracteres = leitor(br);
int minMinusculas = leitor(br);
int minMaiusculas = leitor(br);
int minNumeros = leitor(br);
String senha = br.readLine();
int contaMinusculas = 0;
int contaMaiusculas = 0;
int contaNumeros = 0;
int comprimento = senha.length();
if (comprimento >= minCaracteres) {
for (int i = 0; i < comprimento; i++) {
int valor = senha.charAt(i)-'0';
if (valor >= 0 && valor <= 9) {
contaNumeros++;
}
else if (valor >= 17 && valor <= 42) {
contaMaiusculas++;
}
else if (valor >= 49 && valor <= 74) {
contaMinusculas++;
}
}
if (contaNumeros >= minNumeros && contaMaiusculas >= minMaiusculas && contaMinusculas >= minMinusculas) {
bw.write("Ok =/\n");
}
else {
bw.write("Ufa :)\n");
}
}
else {
bw.write("Ufa :)\n");
}
bw.flush();
bw.close();
return;
}
}
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
while (true) {
n = br.read();
if (n >= '0' && n <= '9') break;
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9') break;
}
return resp;
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int minCaracteres = leitor(br);
int minMinusculas = leitor(br);
int minMaiusculas = leitor(br);
int minNumeros = leitor(br);
String senha = br.readLine();
int contaMinusculas = 0;
int contaMaiusculas = 0;
int contaNumeros = 0;
int comprimento = senha.length();
if (comprimento >= minCaracteres) {
for (int i = 0; i < comprimento; i++) {
int valor = senha.charAt(i)-'0';
if (valor >= 0 && valor <= 9) {
contaNumeros++;
}
else if (valor >= 17 && valor <= 42) {
contaMaiusculas++;
}
else if (valor >= 49 && valor <= 74) {
contaMinusculas++;
}
}
if (contaNumeros >= minNumeros && contaMaiusculas >= minMaiusculas && contaMinusculas >= minMinusculas) {
bw.write("Ok =/\n");
}
else {
bw.write("Ufa :)\n");
}
}
else {
bw.write("Ufa :)\n");
}
bw.flush();
bw.close();
return;
}
}
Comments
Post a Comment