主頁 > USACO > Section 1.3 Problem 4

Section 1.3 Problem 4

Prime Cryptarithm

——————————————————

The following cryptarithm is a multiplication problem that can be solved by substituting digits from a specified set of N digits into the positions marked with *. If the set of prime digits {2,3,5,7} is selected, the cryptarithm is called a PRIME CRYPTARITHM.

      * * *
   x    * *
    -------
      * * *         <-- partial product 1
    * * *           <-- partial product 2
    -------
    * * * *

Digits can appear only in places marked by `*’. Of course, leading zeroes are not allowed.

Note that the ‘partial products’ are as taught in USA schools. The first partial product is the product of the final digit of the second number and the top number. The second partial product is the product of the first digit of the second number and the top number.

Write a program that will find all solutions to the cryptarithm above for any subset of digits from the set {1,2,3,4,5,6,7,8,9}.

——————————————————

PROGRAM NAME: crypt1

——————————————————

INPUT FORMAT

Line 1: N, the number of digits that will be used
Line 2: N space separated digits with which to solve the cryptarithm

——————————————————

SAMPLE INPUT (file crypt1.in)

5
2 3 4 6 8

——————————————————

OUTPUT FORMAT

A single line with the total number of unique solutions. Here is the single solution for the sample input:

      2 2 2
    x   2 2
     ------
      4 4 4
    4 4 4
  ---------
    4 8 8 4

——————————————————

SAMPLE OUTPUT (file crypt1.out)

1

/////////////////////////////////////////////////////

我的答案

http://nopaste.csie.org/3d304

/////////////////////////////////////////////////////

自我檢討

程式碼寫得有點長

有些函數可以用巨集取代

廣告
分類:USACO 標籤:
  1. 仍無迴響。
  1. No trackbacks yet.

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com 標誌

您的留言將使用 WordPress.com 帳號。 登出 /  變更 )

Google photo

您的留言將使用 Google 帳號。 登出 /  變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 /  變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 /  變更 )

連結到 %s

%d 位部落客按了讚: