Prime Cryptarithm
来源:互联网 发布:网络教育本科怎么报考 编辑:程序博客网 时间:2024/05/21 23:34
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
煞笔一开始没有用标记法,错了都不知道哪里找。
/*ID: des_jas1PROG: crypt1LANG: C++*/#include <iostream>#include <fstream>#include <string.h>//#define fin cin//#define fout coutusing namespace std;int N,set[10];bool used[10];int main() {ofstream fout ("crypt1.out"); ifstream fin ("crypt1.in");int i,j,r,k,q,count=0;int a,b,c,d;fin>>N;memset(used,0,sizeof(used));for(i=0;i<N;i++){fin>>set[i];used[set[i]]=true;}for(i=0;i<N;i++) for(r=0;r<N;r++)for(j=0;j<N;j++)for(k=0;k<N;k++)for(q=0;q<N;q++){a=set[i]*100+set[r]*10+set[j];b=a*set[k];c=a*set[q];d=b+c*10;if(b>1000 || c>1000 || d>10000)continue;if(!used[b%10] ||!used[c%10] || !used[d%10])continue;b/=10;c/=10;d/=10;if(!used[b%10] || !used[c%10] || !used[d%10])continue;d/=10;if(!used[b/10] || !used[c/10] || !used[d%10] || !used[d/10])continue;count++;}fout<<count<<endl;fout.close();fin.close(); return 0;}
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- USACO Prime Cryptarithm Accepted
- Prime Cryptarithm(USACO)
- USACO 1.3-Prime Cryptarithm
- 1.3.5 Prime Cryptarithm
- Section 1.4 Prime Cryptarithm
- [USACO] Prime Cryptarithm
- Prime Cryptarithm牛式
- USACO 1.3 Prime Cryptarithm
- 1.3.4 Prime Cryptarithm
- USACO Prime Cryptarithm
- HTML5技术标准初步定稿:功能日益完善
- string的应用
- 增强for循环(jkd1.5)
- Java学习笔记-HashMap
- 十七周:利用指针排序
- Prime Cryptarithm
- C++对象模型(1)——关于对象
- Hibernate1
- 两年三件事
- 【CSDN博客之星】您的支持就是我最大的动力!喜欢本博客的读者,请拿出您宝贵的几秒钟时间来支持一下吧,非常感谢~
- TextView属性大全
- lua的编译、运行
- COM组件中使用用户自定义数据类型
- 关于更改MYECLIPSE JS 代码背景颜色