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

USACO Section 1.2 : Dual Palindromes

dualpal.c
# include <stdio.h>
int N,S;
int count=0;
char num[11]="0123456789";
char n[21];


jinzhi(
int i,int njz)
{
   memset(n,
'\0',sizeof(n));
   
int j=0;
   
char t;
   
int x=0,y;
   
while(i>=njz)
   {
      n[j]
=num[i%njz];
      i
/=njz;
      j
++;
      }

   
if (i==0)
      n[j]
='\0';
   
else
      n[j]
=num[i],n[j+1]='\0';
   y
=strlen(n)-1;
   
while (x<=y)
   {
      t
=n[x];
      n[x]
=n[y];
      n[y]
=t;
      x
++;
      y
--;
      }
}
int palindromic()
{
   
int i=0,j;
   j
=strlen(n)-1;
   
while (i<=j)
   {
      
if (n[i]!=n[j]) return (0);
      i
++;
      j
--;
      }
   
return (1);
}

main ()
{
   FILE 
*in=fopen("dualpal.in","r");
   FILE 
*out=fopen("dualpal.out","w");
   
int i,j,right;
   fscanf (
in,"%d%d",&N,&S);
   
for (i=S+1;count<N;i++)
   {
      right
=0;
      
for (j=2;j<=10;j++)
      {
         jinzhi(i,j);
         
if (palindromic()==1)
            right
++;
         
if (right==2) break;
         }
      
if (right==2)
      {
         fprintf(
out,"%d\n",i);
         count
++;
         }
      }

   fclose(
in);
   fclose(
out);
   exit(
0);
}
posted @ 2009-08-01 18:32  锦燕云  阅读(132)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3