• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
锦燕云
博客园    首页    新随笔    联系   管理    订阅  订阅

USACO Section 1.3 : Prime Cryptarithm

# include <stdio.h>
# include 
<math.h>
# include 
<string.h>

int i,j,k,N,t,s1,s2,num;
int f[11]={0};

check(
int a)
{
   
while (a>0) 
   {
      
if (!f[a%10])
         
return 0;
      a
/=10;      
   }     
   
return 1;
}



main ()
{
   FILE 
*in=fopen("crypt1.in","r");
   FILE 
*out=fopen("crypt1.out","w");
   fscanf (
in,"%d",&N);
   
for (i=1;i<=N;i++)
   {
      fscanf (
in,"%d",&t);
      f[t]
=1;
      }
      
   num
=0;
   
for (i=100;i<1000;i++)
   {
      
if (check(i))
      {
         
for (j=10; j<99; j++)
         {
             
if (check(j))
             {
                s1
=(j%10)*i;
                s2
=(j/10)*i;
                
if ((s1>999)||(!check(s1))) continue;
                
if ((s2>999)||(!check(s2))) continue;
                
if (!check(s2*10+s1)) continue;
                num
++;
                }
             }
         }
      }
   fprintf (
out,"%d\n",num);
   fclose(
in);
   fclose(
out);
   exit (
0);
}
posted @ 2009-08-01 18:38  锦燕云  阅读(220)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3