ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1014. Product of Digits

Tell me what do you think:
Posted by J_Leno 5 Jan 2008 09:31
I've finally managed to get the ACCEPTED message and i'm quite satisfied with that... had to change 2-3 conceipt ideas... At the end may be not the best i could write but please tell me what do you think about the source:


#include <stdio.h>
int main(void)
{
 unsigned long int aa;
 scanf("%ld",&aa);
 int dvoiki=0,troiki=0,petici=0,sedmici=0,chetvorki=0,devetki=0,shestici=0,osmici=0;
 switch(aa){
            case 0:
                 printf("10");
                 break;
            case 1:
                 printf("1");
                 break;
            default:
              for (int j=2;j<=9;j++)if(aa%j==0)
                      {switch (j){
                               case 2:
                                    dvoiki++;
                                    break;
                               case 3:
                                    troiki++;
                                    break;
                               case 5:
                                    petici++;
                                    break;
                               case 7:
                                    sedmici++;
                                    break;
                                    }
                      aa=aa/j--;
                      }
          osmici=dvoiki/3;
          dvoiki=dvoiki%3;
           devetki=troiki/2;
            troiki=troiki%2;
          if ((dvoiki>1)&&(troiki>0)) {dvoiki--;troiki--;shestici++;}
          if ((dvoiki>0)&&(troiki>2)) {dvoiki--;troiki--;shestici++;}
          if ((dvoiki>0)&&(troiki>0)) {dvoiki--;troiki--;shestici++;}

          chetvorki=dvoiki/2;
          dvoiki=dvoiki%2;

          if (aa>7) printf("-1");
          else{
          for(int i=1;i<=dvoiki;i++)printf("2");
          for(int i=1;i<=troiki;i++)printf("3");
          for(int i=1;i<=chetvorki;i++)printf("4");
          for(int i=1;i<=petici;i++)printf("5");
          for(int i=1;i<=shestici;i++)printf("6");
          for(int i=1;i<=sedmici;i++)printf("7");
          for(int i=1;i<=osmici;i++)printf("8");
          for(int i=1;i<=devetki;i++)printf("9");
          }
}
return 0;
}
Re: Tell me what do you think:
Posted by Melifaro 15 Feb 2008 19:59
I think C# RULIT
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1014
{
    class Program
    {
        static void Main(string[] args)
        {
            string result = "";
            int num = int.Parse(Console.ReadLine());
            if (num == 1)
                Console.WriteLine("1");
            else
            {
                if (num == 0)
                    Console.WriteLine("10");
                else
                {
                    int[] digitArr = new int[10];
                    for (int i = 9; i > 1; i--)
                    {
                        while (num % i == 0)
                        {
                            digitArr[i]++;
                            num /= i;
                        }
                    }
                    if (num != 1)
                        Console.WriteLine("-1");
                    else
                    {
                        for (int i = 2; i < 10; i++)
                        {
                            for (int j = 0; j < digitArr[i]; j++)
                                result += i.ToString();
                        }
                        Console.WriteLine(result);
                    }
                }
            }
        }
    }
}