(SPOJ) 2844 - Você pode dizer 11 - 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));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
while((line = br.readLine()) != null) {
if (line.length() == 1 && line.charAt(0) == '0') {
return;
}
int pares = 0;
int impares = 0;
for (int i = 0; i < line.length(); i=i+2) {
pares += (line.charAt(i)-'0');
}
for (int i = 1; i < line.length(); i=i+2) {
impares += (line.charAt(i)-'0');
}
if (((impares+11-pares)%11) != 0) {
bw.write(line + " is not a multiple of 11.\n");
}
else {
bw.write(line + " is a multiple of 11.\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);
}
void processa() throws NumberFormatException, IOException {
String line = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
while((line = br.readLine()) != null) {
if (line.length() == 1 && line.charAt(0) == '0') {
return;
}
int pares = 0;
int impares = 0;
for (int i = 0; i < line.length(); i=i+2) {
pares += (line.charAt(i)-'0');
}
for (int i = 1; i < line.length(); i=i+2) {
impares += (line.charAt(i)-'0');
}
if (((impares+11-pares)%11) != 0) {
bw.write(line + " is not a multiple of 11.\n");
}
else {
bw.write(line + " is a multiple of 11.\n");
}
bw.flush();
}
bw.close();
return;
}
}
Comments
Post a Comment