电子科技大学中山学院ACM部分答案.docx
《电子科技大学中山学院ACM部分答案.docx》由会员分享,可在线阅读,更多相关《电子科技大学中山学院ACM部分答案.docx(17页珍藏版)》请在冰豆网上搜索。
电子科技大学中山学院ACM部分答案
ACM1037
#include
intmain()
{
intsum1,sum2,n,i,m,t;
while(scanf("%d%d",&m,&n)!
=EOF)
{
sum1=sum2=0;
if(m>n){t=m;m=n;n=t;}
for(i=m;i<=n;i++)
{
if(i%2==0)sum1+=(i*i);
elsesum2+=(i*i*i);
}
printf("%d%d\n",sum1,sum2);
}
return0;
}
ACM1039
#include
#include
main()
{
doublen,m,s,w,i;
while(scanf("%lf%lf",&n,&m)!
=EOF)
{
s=n;
for(i=1;i{
n=sqrt(n);
s=s+n;
}
printf("%.2lf\n",s);
}
}
ACM1041
#include
intmain()
{
intx,y,sum,i,count,n;
while(scanf("%d%d",&x,&y)!
=EOF&&(x!
=0||y!
=0))
{
count=0;
for(n=x;n<=y;++n)
{
sum=n*n+n+41;
for(i=2;i*i<=sum;++i)
{
if(sum%i==0)
count=1;
}
}
if(count==0)
printf("OK\n");
else
printf("Sorry\n");
}
return0;
}
ACM1042
#include
intmain()
{
intn,i;
doublesum,averge,max,min,score;
while(scanf("%d",&n)!
=EOF)
{
scanf("%lf",&score);
max=score;
min=score;
sum=score;
for(i=2;i<=n;i++)
{
scanf("%lf",&score);
if(score>max)
max=score;
if(scoremin=score;
sum+=score;
}
averge=(sum-max-min)/(n-2);
printf("%.2f\n",averge);
}
return0;
}
ACM1043
#include
main()
{
intn,m,a,b,i,j,k,w,l,e,s,d,r;
while(scanf("%d%d",&n,&m)!
=EOF)
{
s=0;
e=0;
l=0;
if(n<=m)
{
for(i=0;i{
s=s+2;
e=e+s;
k=e/n;
}
printf("%d\n",k);
}
else
{
w=n%m;
r=0;
for(i=1;i<=n-w;i++)
{
s=s+2;
l=l+s;
e=e+s;
if(i%m==0)
{
k=e/m;
e=0;
if(r)
printf("");
printf("%d",k);
r=r+1;
}
}
s=0;
if(w!
=0)
{
for(j=0;j{
s=s+2;
e=e+s;
}
d=e-l;
k=d/w;
printf("");
printf("%d",k);
}
printf("\n");
}
}
}
ACM1044
数据交换输出
#include
intmain()
{
intn,i,k,a[100],min,temp;
while(scanf("%d",&n)!
=EOF&&n!
=0){
scanf("%d",&a[0]);
min=a[0];
k=0;
for(i=1;iscanf("%d",&a[i]);
if(a[i]min=a[i];
k=i;
}
}
temp=a[0];
a[0]=min;
a[k]=temp;
for(i=1;i<=n;++i)
{
if(i!
=1)
printf("");
printf("%d",a[i-1]);
}
printf("\n");
}
return0;
}
ACM1045
#include
intmain(){
intnum,n,i;
charline;
scanf("%d",&n);
getchar();
for(i=1;i<=n;++i){
num=0;
for(;(line=getchar())!
='\n';)
{
if(line>='0'&&line<='9')
num++;
}
printf("%d\n",num);
}
return0;
}
ACM1047
#include
main()
{
intn,m,a[100],b[100],i,j,k,s,w,d;
scanf("%d%d",&n,&m);
while(!
(n==0&&m==0))
{
w=0;
for(i=0;iscanf("%d",&a[i]);
s=a[0];
if(m
{
printf("%d",m);
for(j=0;j{
printf("");
printf("%d",a[j]);
}
}
else
{
for(j=0;j{
if(m>a[j])
w=w+1;
}
for(j=0;j{
printf("%d",a[j]);
printf("");
}
printf("%d",m);
for(j=w;j{
printf("");
printf("%d",a[j]);
}
}
printf("\n");
scanf("%d%d",&n,&m);
}
}
ACM1048
#include
main()
{
intn,m,a[100],b[100],c,d,e,f,i,j,k;
while(scanf("%d",&n)!
=EOF&&n!
=0)
{
for(i=0;iscanf("%d",&a[i]);
f=0;
for(j=0;j{
c=0;
for(i=0;i{
if(a[i]<0)
m=-a[i];
elsem=a[i];
if(c<=m)
{
c=m;
b[j]=a[i];
k=i;
}
}
a[k]=0;
if(f)
printf("");
printf("%d",b[j]);
f=f+1;
}
printf("\n");
}
}
ACM1049
#include
main()
{
intn,m,a,b,c,d,e,f,i,j,k;
while(scanf("%d",&n)!
=EOF&&n!
=0)
{
k=0;
for(i=0;i{
scanf("%d",&m);
a=m/100;
b=m%100/50;
c=m%100%50/10;
d=m%100%50%10/5;
e=m%100%50%10%5/2;
f=m%100%50%10%5%2;
k=k+a+b+c+d+e+f;
}
printf("%d\n",k);
}
}
ACM1052
#include
intmain(){
intn,i,j,frag;
charline[50];
while(scanf("%d",&n)!
=EOF){
getchar();
for(i=1;i<=n;++i){
j=0;frag=0;
while((line[j]=getchar())!
='\n'){
if(!
((line[j]=='_')||(line[j]>='0'&&line[j]<='9')||(line[j]>='A'&&line[j]<='Z')||(line[j]>='a'&&line[j]<='z')))
frag=1;
if(line[0]>='0'&&line[0]<='9'){
frag=1;
}
++j;
}
if(frag==0)
printf("yes");
else
printf("no");
printf("\n");
}
}
return0;
}
ACM1053
#include
intmain(){
inti,max,n,j,line[100];
while((line[0]=getchar())!
=EOF){
max=line[0];
i=1;
for(;(line[i]=getchar())!
='\n';++i){
if(line[i]>max){
max=line[i];
}
}
n=i;
for(j=0;j<=n;++j){
if(line[j]==max){
printf("%c",line[j]);
printf("(max)");
}
else
printf("%c",line[j]);
}
//printf("\n");
}
return0;
}
ACM1061
#include
main()
{inti,j,a,b,c,d,e,f,n,s;
while(scanf("%d",&n)!
=EOF)
{c=0;d=0;e=0;
for(i=0;i{a=0;b=0;c=0;d=0;e=0;f=0;
scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
a=a+d;
b=b+e;c=c+f;
j=0;
while(c>60)
{
c=c-60;
j=j+1;
}
b=b+j;
s=0;
while(b>60)
{
b=b-60;
s=s+1;
}
a=a+s;
printf("%d%d%d\n",a,b,c);
}
}
}
ACM1066
#include
main()
{
doublen,a,b,c,i;
while(scanf("%lf",&n)!
=EOF)
{
for(i=0;i{
scanf("%lf%lf%lf",&a,&b,&c);
if((a+b)>c&&(b+c)>a&&(a+c)>b)
printf("YES\n");
else
printf("NO\n");
}
}
}
ACM1067
#include
main()
{
doublen,a,b,c,i;
while(scanf("%lf",&n)!
=EOF)
{
for(i=0;i{
scanf("%lf%lf%lf",&a,&b,&c);
if((a+b)>c&&(b+c)>a&&(a+c)>b)
printf("YES\n");
else
printf("NO\n");
}
}
}