USACO CRYPT1

USACO CRYPT1

ID:42722081

大小:33.00 KB

页数:3页

时间:2019-09-20

USACO CRYPT1_第1页
USACO CRYPT1_第2页
USACO CRYPT1_第3页
资源描述:

《USACO CRYPT1》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、PrimeCryptarithmThefollowingcryptarithmisamultiplicationproblemthatcanbesolvedbysubstitutingdigitsfromaspecifiedsetofNdigitsintothepositionsmarkedwith*.Ifthesetofprimedigits{2,3,5,7}isselected,thecryptarithmiscalledaPRIMECRYPTARITHM.***x**-------***<--partialproduct1***<--partialproduct2-

2、------****Digitscanappearonlyinplacesmarkedby`*'.Ofcourse,leadingzeroesarenotallowed.Notethatthe'partialproducts'areastaughtinUSAschools.Thefirstpartialproductistheproductofthefinaldigitofthesecondnumberandthetopnumber.Thesecondpartialproductistheproductofthefirstdigitofthesecondnumberand

3、thetopnumber.Writeaprogramthatwillfindallsolutionstothecryptarithmaboveforanysubsetofdigitsfromtheset{1,2,3,4,5,6,7,8,9}.PROGRAMNAME:crypt1INPUTFORMATLine1:N,thenumberofdigitsthatwillbeusedLine2:NspaceseparateddigitswithwhichtosolvethecryptarithmSAMPLEINPUT(filecrypt1.in)523468OUTPUTFORMA

4、TAsinglelinewiththetotalnumberofuniquesolutions.Hereisthesinglesolutionforthesampleinput:222x22------444444---------4884SAMPLEOUTPUT(filecrypt1.out)1{ID:hyysmmu1PROG:crypt1LANG:PASCAL}vari,j,k,m,n,ans:longint;a1:longint;a:array[1..9]ofboolean;functioncheck(kk:longint):boolean;begincheck:=

5、false;whilekk>0dobeginifnota[kkmod10]thenexit;kk:=kkdiv10;end;check:=true;end;proceduresub(k1:longint);vari1,m1,m2,m3:longint;beginifk1=6thenbeginm1:=a1mod10;m2:=a1mod100;m3:=a1div100;if(m2*m3>=1000)and(m2*m3<=9999)and(m1*m3<1000)and(m1*m3>=100)andcheck(m2*m3)andcheck(m1*m3)theninc(ans);e

6、xit;end;ifk1=5thenbeginm1:=a1mod10;m2:=a1div10;if(m1*m2>=1000)or(m1*m2<100)ornotcheck(m1*m2)thenexit;end;fori1:=1to9doifa[i1]thenbegina1:=a1*10+i1;sub(k1+1);a1:=a1div10;end;end;beginassign(input,'crypt1.in');assign(output,'crypt1.out');reset(input);rewrite(output);ans:=0;fillchar(a,sizeof

7、(a),false);readln(n);fori:=1tondobeginread(m);a[m]:=true;end;a1:=0;sub(1);writeln(ans);close(input);close(output);end.

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。