ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1014. Произведение цифр

WHat is test 4?
Послано Elbek 4 окт 2012 07:21
Here is My code and, what is wrong?

import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * User: elbek
 * Date: 10/3/12
 * Time: 7:05 PM
 */
public class TImus1014 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextLong();
        System.out.println(getSmall(a));
    }

    private static String getSmall(Long input) {

        if(input==1 || input==0)
            return  input.toString();

        int delim[] = {2, 3, 5, 7};
        int delimIndex = 0;
        Map<Integer, Integer> product = new TreeMap<Integer, Integer>();
        while (delimIndex < 4) {
            if (input % delim[delimIndex] == 0) {
                input = input / delim[delimIndex];
                if (product.containsKey(delim[delimIndex])) {
                    int val = product.get(delim[delimIndex]);
                    product.put(delim[delimIndex], ++val);
                } else
                    product.put(delim[delimIndex], 1);
            } else delimIndex++;
            if (input < 2)
                break;
        }
        if (input != 1 || product.size()==0)
            return "-1";

        StringBuilder result = new StringBuilder();
        if (product.containsKey(2)) {
            while (true) {
                int count = product.get(2);
                if (count > 2) {
                    product.put(2, count - 3);
                    int key = (int) Math.pow(2, 3);
                    if (!product.containsKey(key)) {
                        product.put(key, 0);
                    }
                    int val = product.get(key);
                    product.put(key, ++val);
                } else {
                    if (product.get(2) == 0)
                        product.remove(2);
                    break;
                }
            }
        }

        if (product.containsKey(3)) {
            while (true) {
                int count = product.get(3);
                if (count > 1) {
                    product.put(3, count - 2);
                    int key = (int) Math.pow(3, 2);
                    if (!product.containsKey(key)) {
                        product.put(key, 0);
                    }
                    int val = product.get(key);
                    product.put(key, ++val);
                } else {
                    if (product.get(3) == 0)
                        product.remove(3);
                    break;
                }
            }
        }

        if (product.containsKey(3)) {
            if (product.containsKey(2)) {
                int count = product.get(2);
                product.put(6, 1);
                count--;
                product.put(2, count);
                product.remove(3);
            }
        } else if (product.containsKey(2)) {
            if (product.get(2) == 2) {
                product.remove(2);
                product.put(4, 1);
            }
        }

        for (Map.Entry<Integer, Integer> key : product.entrySet()) {
            for (int i = 0; i < key.getValue(); i++) {
                result.append(key.getKey());
            }
        }
        return result.toString();

    }
}
Re: WHat is test 4?
Послано Iftekher Toufique Imam 5 фев 2018 08:01
try 0
for this ans will be 10