栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2159 Base Numbers

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2159 Base Numbers

#include <stdio.h>#include <string.h>char st[40],num[40],*base;int lenb;long long f[40],ans;int minx(int x,int y){return (x<y)?x:y;}int cmp(int l,int r){ int i; for (i=l; i<r; ++i)  num[i-l]=st[i]; num[r-l]=''; return strcmp(num,base);}void count(int x){ int i,j,k; for (i=x-1; i>=0; --i)  if (st[i]!='0') {   k=minx(i+lenb,x);   for (j=i+1; j<=k; ++j)    if (j-i<lenb || j-i==lenb && cmp(i,j)<0)     f[i]+=f[j];  } else   f[i]+=f[i+1];}int main(){ int i,j; while (scanf("%s",st),st[0]!='#') {  if (st[0]=='0') {   printf((st[1]=='' || st[1]=='0' || st[1]=='1' && st[2]=='')?"The pre %s is invalid.n":"The pre %s can represent 1 numbers.n",st);   continue;  }  ans=0;  for (i=(int)strlen(st)-1,j=1; i; --i,++j)   if (st[i]!='0') {    memset(f,0,sizeof(f));    f[i]=1;    base=st+i;    lenb=j;    count(i);    ans+=f[0];   }  (ans)?printf("The pre %s can represent %lld numbers.n",st,ans):printf("The pre %s is invalid.n",st); } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379047.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号