您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > 西工大C语言POJ作业
T081、阶乘合计#includestdio.hintfun(intn){inti,m=1,sum=0;for(i=1;i12;i++){m*=i;sum+=m;if(n==m)return1;if(mn)break;}if(sum-mn)return0;elsereturnfun(n-m/i);}intmain(){intn;scanf(%d,&n);if(fun(n))printf(YES\n);elseprintf(NO\n);return0;}T082、路痴#includestdio.hintmain(){charfx[5];intn,i,d,j;scanf(%s%d,fx,&n)!=EOF;{switch(fx[0]){case'S':d=0;break;case'E':d=1;break;case'N':d=2;break;case'W':d=3;break;}for(i=0;in;i++){scanf(%d,&j);if(j==0)d++;elsed--;}d%=4;switch(d=0?d:d+4){case0:printf(South\n);break;case1:printf(East\n);break;case2:printf(North\n);break;case3:printf(West\n);break;}}return0;}T083、三点顺序#includestdio.hintmain(){intx1,y1,x2,y2,x3,y3;scanf(%d%d%d%d%d%d,&x1,&y1,&x2,&y2,&x3,&y3);{if((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1)0)printf(0\n);//逆时针elseprintf(1\n);//顺时针}return0;}T084、TheRatioofgainerstolosers#includestdio.h#includemath.hintmain(){inta,b,p,q,p1,q1;scanf(%d%d,&a,&b);p=1,q=0;for(q1=1;q1=b;q1++){p1=(double)(q1*a)/(double)b+0.5;if(q*fabs(a*q1-b*p1)q1*fabs(a*q-b*p)){q=q1;p=p1;printf(%d/%d\n,p,q);}if(a*q==b*p)break;}return0;}T085、最长回文子串#includestdio.h#includestring.h#includectype.hintmain(){chars[5001],s1[5000];intpri[5000],max=0,len,i,j,x,y,m=0;gets(s);len=strlen(s);for(i=0;ilen;++i){if(isalpha(s[i]))//是否为字母{pri[m]=i;//保存实际位置s1[m++]=toupper(s[i]);//转换为大写字母}}for(i=0;ilen;i++){for(j=0;i-j=0&&i+jlen;j++){if(s1[i-j]!=s1[i+j])break;if(2*j+1max){max=2*j+1;x=pri[i-j];y=pri[i+j];}}for(j=0;i-j=0&&i+jlen;j++){if(s[i-j]!=s1[i+j+1])break;if(2*j+2max){max=2*j+2;x=pri[i-j];y=pri[i+j+1];}}}for(i=x;i=y;i++)printf(%c,s[i]);printf(\n);return0;}T086、Easyproblem#includestdio.h#includemath.h#includestdlib.hintmain(){intk;longlongi,N;{k=0;scanf(%I64d,&N);for(i=1;(i+1)*(i+1)=N+1;i++){if((N+1)%(i+1)==0){k++;}}printf(%d\n,k);}return0;}T087、Hailstone#includestdio.h#definemax(a,b)ab?a:b#definemin(a,b)ab?b:aintmain(){inta,b,m,n,max,count,k;scanf(%d%d,&a,&b);m=max(a,b);n=min(a,b);max=0;for(;n=m;n++){k=n;count=1;while(k!=1){if(k%2==1)k=3*k+1;elsek/=2;count++;}if(countmax)max=count;}printf(%d%d%d\n,a,b,max);return0;}T088、公园喷水器#includestdio.h#includemath.hintmain(){floata[600],t,sum=0;intn,i,j;scanf(%d,&n);for(i=0;in;i++)scanf(%f,&a[i]);for(i=0;in;i++)for(j=i+1;jn;j++)if(a[i]a[j]){t=a[i];a[i]=a[j];a[j]=t;}i=0;//要使喷水装置半径和草坪宽度的一半组成的直角三角形的另一边长度和大于等于20while(sum20){sum+=2*sqrt(a[i]*a[i]-1);i++;}printf(%d\n,i);return0;}T089、操场训练#includestdio.h#includemath.hintmain(){inti,j,t,a[10000],b[10000],n,x,sum=0;scanf(%d,&n);for(i=0;in;i++)scanf(%d%d,&a[i],&b[i]);for(i=0;in;i++)for(j=i+1;jn;j++)if(a[i]a[j]){t=a[j];a[j]=a[i];a[i]=t;}for(i=0;in;i++)for(j=i+1;jn;j++)if(b[i]b[j]){t=b[j];b[j]=b[i];b[i]=t;}for(i=0;in;i++)a[i]-=i;for(i=0;in;i++)for(j=i+1;jn;j++)if(a[i]a[j]){t=a[j];a[j]=a[i];a[i]=t;}x=(n+1)/2-1;for(i=0;in;i++)sum+=(fabs(b[x]-b[i])+fabs(a[x]-a[i]));printf(%d\n,sum);return0;}T090、A*B#includestdio.hintmain(){intk;longa,b;scanf(%ld%ld,&a,&b);if(a==0||b==0)printf(0\n);else{k=(a%9)*(b%9)%9;if(k==0)printf(9\n);elseprintf(%d\n,k);}return0;}
本文标题:西工大C语言POJ作业
链接地址:https://www.777doc.com/doc-5840885 .html