资源描述:
《2011年蓝桥杯预赛题目答案》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、//预赛NO.1题#includevoidmain(){intJC[]={1,1,2,6,24,120,720,5040,40320,};inti;intsum;intx;for(i=100;i<1000;i++){sum=0;x=i;while(x){sum+=JC[x%10];x/=10;}if(i==sum){printf("%d",i);}}}#includevoidmain(){doublex[10]={7,8,8,8,8,20,8,8,8,8};inti,j;double
2、dif=-1;doublebad;doublesum;intn=10;doublet;for(i=0;i<10;i++){sum=0;for(j=0;jdif){dif=t;bad=x[i];printf("%d,%f",i,x[i]);}}printf("bad=%lf",bad);}//预赛NO.3题#include#includevoidreverse
3、_str(char*buf,intn){chartmp;if(n<2)return;tmp=buf[0];buf[0]=buf[n-1];buf[n-1]=tmp;reverse_str(buf+1,n-2);}voidmain(){chara[10]="zhanghe";reverse_str(a,strlen(a));printf("%s",a);}#includevoidfun(doubledTestNo,intiBase){intiT[8];intiNo;printf("十进制正小数%f转换成
4、%d进制数为:",dTestNo,iBase);for(iNo=0;iNo<8;iNo++){dTestNo*=iBase;iT[iNo]=(int)dTestNo;if(dTestNo)dTestNo-=iT[iNo];}printf("0.");for(iNo=0;iNo<8;iNo++)printf("%d",iT[iNo]);printf("");}voidmain(){doubledTestNo=0.795;intiBase;for(iBase=2;iBase<=9;iBase++)fun(dTestNo,i
5、Base);printf("");}#include#include#includevoidshift(char*s,intn){char*p;char*q;intlen=strlen(s);char*s2;if(len==0)return;if(n<=0
6、
7、n>=len)return;s2=(char*)malloc(sizeof(char)*(len+1));p=s;q=s2+n%len;while(*p){*q++=*p++;if(q-s2>=len){*
8、q=' ';q=s2;}}strcpy(s,s2);free(s2);}voidmain(){charstr[10]="zhanghe";shift(str,2);printf("%s",str);}//预赛NO.6题#include#includeintg(inta,intb)//b是摇号产生的{charsa[]="";charsb[]="";intn=0;inti,j;chart;sprintf(sa,"%8d",a);sprintf(sb,"%8d",b);for(i=0;
9、i<8;i++){for(j=1;j<=8-i;j++){t=sa[i+j];sa[i+j]=0;if(strstr(sb,sa+i)){if(j>n)n=j;}sa[i+j]=t;}}returnn;}voidmain(){inta=;intb=;printf("%d",g(a,b));}预赛NO.7题#include/*m:袋中红球的数目n:袋中白球的数目x:需要取出的数目y:红球至少出现的次数*/doublepro(intm,intn,intx,inty){doublep1;doublep2;i
10、f(y>x)return0;if(y==0)return1;if(y>m)return0;if(x-n>y)return1;p1=pro(m-1,n,x-1,y-1);//取红球p2=pro(m,n-1,x-1,y);//取白球return(double)m/(m+n)*p1+(double)n/(m+