Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class main {
- public static Scanner s = new Scanner(System.in);
- public static int somaAlgs(int n) {
- int soma = 0;
- for (byte b : Integer.toString(n).getBytes())
- if ((b - 48) == 0)
- return 0;
- else
- soma += (b - 48);
- return soma;
- }
- public static double combin(int total, int combinados) {
- return fat(total) / (fat(combinados) * fat(total - combinados));
- }
- public static double fat(int n) {
- if (n <= 1)
- return 1;
- else
- return (n *= fat(n - 1));
- }
- public static int unificar(int n) {
- int res = 1;
- for (int i = 1; i < Integer.toString(n).length(); i++) {
- res *= 10;
- res++;
- }
- return res;
- }
- public static String mask(int n, int d) {
- String buffer = "";
- int tamanhoD = Integer.toString(d).length() * 3;
- for (int i = 0; i < tamanhoD; i++) {
- if ((int) (tamanhoD / 2) - 1 == i)
- buffer += n + "!";
- buffer += " ";
- }
- buffer += "\n";
- for (int i = 0; i < tamanhoD; i++)
- buffer += "-";
- buffer += " + \n";
- int c = 1;
- for (byte b : Integer.toString(d).getBytes()) {
- buffer += (b - 48) + "!";
- if(c!=Integer.toString(d).length())
- buffer+="*";
- c++;
- }
- buffer += "\n";
- return buffer;
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int garotos = 7;
- int garotas = 2;
- int c = 0;
- for (int i = unificar((int) Math.pow(10, garotas - 1)); i < Math.pow(
- 10, garotas); i++) {
- if (somaAlgs(i) == garotos) {
- System.out.println(mask(garotos, i));
- c++;
- }
- }
- System.out.println(c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement