A - ASCII码排序
http://acm.hdu.edu.cn/showproblem.php?pid=2000
qwe asd zxc
e q w a d s c x z
#include<stdio.h>
int main()
{
char a,b,c;
while(~scanf("%c%c%c",&a,&b,&c))
{
getchar();
int temp;
if(a>b)
{
temp=a;
a=b;
b=temp;
}
if(a>c)
{
temp=a;
a=c;
c=temp;
}
if(b>c)
{
temp=b;
b=c;
c=temp;
}
printf("%c %c %c\n",a,b,c);
}
return 0;
}
0 0 0 1 0 1 1 0
1.00 1.41
#include<stdio.h>
#include<math.h>
int main()
{
double x1,x2,y1,y2;
while(~scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2))
{
printf("%.2lf\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
return 0;
}
C - 计算球体积
1 1.5
4.189
14.137
#define PI 3.1415927
#include<stdio.h>
#define PI 3.1415927
int main()
{
double r;
while(~scanf("%lf",&r))
{
printf("%.3lf\n",(4.0/3.0)*PI*r*r*r);
}
return 0;
}
D - 求绝对值
http://acm.hdu.edu.cn/showproblem.php?pid=2003
123 -234.00
123.00 234.00
#include<stdio.h>
#include<math.h>
int main()
{
double x;
while(~scanf("%lf",&x))
{
printf("%.2lf\n",fabs(x));
}
return 0;
}
E - 成绩转换
http://acm.hdu.edu.cn/showproblem.php?pid=2004
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;
56 67 100 123
E D A Score is error!
#include<stdio.h>
int main()
{
int x;
while(~scanf("%d",&x))
{
if(x<0||x>100)
{
printf("Score is error!\n");
}
else
{
switch(x/10)
{
case 1:
case 2:
case 3:
case 4:
case 5:printf("E\n");break;
case 6:printf("D\n");break;
case 7:printf("C\n");break;
case 8:printf("B\n");break;
case 9:
case 10:printf("A\n");break;
}
}
}
return 0;
}
F - 第几天?
http://acm.hdu.edu.cn/showproblem.php?pid=2005
1985/1/20 2006/3/12
20 71
#include<stdio.h>
int judge(int year,int month,int day)
{
int a[13]={0,0,31,59,90,120,151,181,212,243,273,304,334};
if((year%4==0&&year%100!=0)||(year%400==0))
{
if(month>2)
return a[month]+day+1;
else
return a[month]+day;
}
else
return a[month]+day;
}
int main()
{
int year,month,day;
while(~scanf("%d/%d/%d",&year,&month,&day))
{
printf("%d\n",judge(year,month,day));
}
return 0;
}
G - 求奇数的乘积
http://acm.hdu.edu.cn/showproblem.php?pid=2006
3 1 2 3 4 2 3 4 5
3 15
#include<stdio.h>
int main()
{
int n,x;
while(~scanf("%d",&n))
{
int i,ans=1;
for(i=0;i<n;i++)
{
scanf("%d",&x);
if(x%2)
ans*=x;
}
printf("%d\n",ans);
}
return 0;
}
H - 平方和与立方和
http://acm.hdu.edu.cn/showproblem.php?pid=2007
你可以认为32位整数足以保存结果。
1 3 2 5
4 28 20 152
#include<stdio.h>
int main()
{
int x,y,temp;
while(~scanf("%d%d",&x,&y))
{
if(x>y)
{
temp=x;
x=y;
y=temp;
}
int sum1=0,sum2=0,i;
for(i=x;i<=y;i++)
{
if(i%2==1)
sum2+=i*i*i;
else
sum1+=i*i;
}
printf("%d %d\n",sum1,sum2);
}
return 0;
}
I - 数值统计
http://acm.hdu.edu.cn/showproblem.php?pid=2008
6 0 1 2 3 -1 0 5 1 2 3 4 0.5 0
1 2 3 0 0 5
#include<stdio.h>
int main()
{
int n;
while(~scanf("%d",&n),n)
{
int i,zero=0,plus=0,negative=0;
double x;
for(i=0;i<n;i++)
{
scanf("%lf",&x);
if(x<0.0)
negative++;
else if(x==0.0)
zero++;
else
plus++;
}
printf("%d %d %d\n",negative,zero,plus);
}
return 0;
}
K - 水仙花数
http://acm.hdu.edu.cn/showproblem.php?pid=2010
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。
现在要求输出所有在m和n范围内的水仙花数。
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
100 120 300 380
no 370 371
#include<stdio.h>
int main()
{
int m,n,t,i,j,d[5],g,s,b;
while(~scanf("%d%d",&m,&n))
{
t=0;
for(i=m;i<=n;i++)
{
g=i%10;
s=(i/10)%10;
b=i/100;
if(g*g*g+s*s*s+b*b*b==i)
{
d[t++]=i;
}
}
if(!t)
{
printf("no");
}
else
{
for(j=0;j<t;j++)
{
printf(j==(t-1)?"%d":"%d ",d[j]);
}
}
printf("\n");
}
return 0;
}
L - 多项式求和
http://acm.hdu.edu.cn/showproblem.php?pid=2011
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ...
现在请你求出该多项式的前n项的和。
2 1 2
1.00 0.50
#include<stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
double i,n,sign=1,ans=0;
scanf("%lf",&n);
for(i=1;i<=n;i++)
{
ans+=(1.0/i)*sign;
sign*=-1;
}
printf("%.2lf\n",ans);
}
return 0;
}
http://acm.hdu.edu.cn/showproblem.php?pid=2012
Problem Description
0 1 0 0
OK
#include<stdio.h>
#include<math.h>
int main()
{
int x,y;
while(~scanf("%d%d",&x,&y),(x||y))
{
int i,j,n,flag=1;
for(i=x;i<=y;i++)
{
n=i*i+i+41;
for(j=2;j*j<n;j++)
{
if(n%j==0)
flag=0;
}
}
if(flag)
{
printf("OK\n");
}
else
{
printf("Sorry\n");
}
}
return 0;
}
N - 蟠桃记
http://acm.hdu.edu.cn/showproblem.php?pid=2013
什么问题?他研究的问题是蟠桃一共有多少个!
不过,到最后,他还是没能解决这个难题,呵呵^-^
当时的情况是这样的:
第一天悟空吃掉桃子总数一半多一个,第二天又将剩下的桃子吃掉一半多一个,以后每天吃掉前一天剩下的一半多一个,到第n天准备吃的时候只剩下一个桃子。聪明的你,请帮悟空算一下,他第一天开始吃的时候桃子一共有多少个呢?
2 4
4 22
#include<stdio.h>
#include<stdlib.h>
int f(int n, int x)
{
if (n == 1)
{
return x;
}
else
{
return f(n - 1, (x + 1) * 2);
}
}
int main()
{
int num;
while (scanf("%d", &num) != EOF)
{
printf("%d\n", f(num, 1));
}
return 0;
}
#include<stdio.h>
int main()
{
int n;
while(~scanf("%d",&n))
{
int m=1,i,ans=1;
for(i=2;i<=n;i++)
{
ans=m;
m=((m*2)+1);
ans+=m;
}
printf("%d\n",ans);
}
return 0;
}
O - 青年歌手大奖赛_评委会打分
http://acm.hdu.edu.cn/showproblem.php?pid=2014
3 99 98 97 4 100 99 98 97
98.00 98.50
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
double *p,sum=0,temp;
int i,j,k;
p=(double *)malloc(sizeof(double)*n);
for( i=0;i<n;i++)
{
scanf("%lf",(p+i));
sum+=*(p+i);
}
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(*(p+j)<*(p+k))
{
k=j;
}
}
if(k!=i)
{
temp;
temp=*(p+i);
*(p+i)=*(p+k);
*(p+k)=temp;
}
}
double a=*p;
double b=*(p+n-1);
sum=sum-(a+b);
printf("%.2lf\n",sum/(n-2));
}
}
P - 偶数求和
http://acm.hdu.edu.cn/showproblem.php?pid=2015
3 2 4 2
3 6 3 7
#include<stdio.h>
#define N 105
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
int a[N],ans[N],i,j=1,k;
for(i=1;i<=n;i++)
{
a[i]=i*2;
}
for(i=1;i<=n;i+=(m))
{
k=n-i+1;
if(k>m)
{
ans[j++]=(( (a[i]+a[i+m-1]) )/2);
}
else
{
ans[j]=(a[i]+a[n]) /2;
break;
}
}
for(i=1;i<=j;i++)
{
printf(i==j?"%d\n":"%d ",ans[i]);
}
}
return 0;
}
Q - 数据的交换输出
http://acm.hdu.edu.cn/showproblem.php?pid=2016
4 2 1 3 4 5 5 4 3 2 1 0
1 2 3 4 1 4 3 2 5
#include<stdio.h>
int main()
{
int n,i,j,temp,min,a[105];
while(~scanf("%d",&n),n)
{
scanf("%d",&a[0]);
min=a[0];
for(i=1;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(min>=a[i])
{
min=a[i];
j=i;
}
}
temp=a[0];
a[0]=a[j];
a[j]=temp;
for(i=0;i<n;i++)
{
printf(i==n-1?"%d\n":"%d ",a[i]);
}
}
return 0;
}
R - 字符串统计
http://acm.hdu.edu.cn/showproblem.php?pid=2017
2 asdfasdf123123asdfasdf asdf111111111asdfasdfasdf
6 9
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char a[1000];
int i,len,n,count;
scanf("%d",&n);
while(n--)
{
count=0;
scanf("%s",a);
for(i=0;i<strlen(a);i++)
{
if(isdigit(a[i]))
count++;
}
printf("%d\n",count);
}
return 0;
}
S - 母牛的故事
http://acm.hdu.edu.cn/showproblem.php?pid=2018
n=0表示输入数据的结束,不做处理。
每个输出占一行。
2 4 5 0
2 4 6
#include<stdio.h>
int a[100]={
0,1,2,3,4
};
void solve()
{
for(int i=5;i<=60;i++)
{
a[i]=a[i-1]+a[i-3];
}
}
int main()
{
int n;
solve();
while(~scanf("%d",&n),n)
{
printf("%d\n",a[n]);
}
return 0;
}
T - 数列有序!
http://acm.hdu.edu.cn/showproblem.php?pid=2019
3 3 1 2 4 0 0
1 2 3 4
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m),(n||m))
{
int *a,i,flag=-1;
a=(int *)calloc(n,sizeof(n));
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]>=m&&flag==-1)
{
flag=i;
}
}
for(i=0;i<n;i++)
{
printf((i==n-1&&i!=flag)?"%d\n":"%d ",i==flag?m:a[i]);
if(i==flag)
{
flag=-1; i--;
}
}
}
return 0;
}
U - 绝对值排序
http://acm.hdu.edu.cn/showproblem.php?pid=2020
3 3 -4 2 4 0 1 2 -3 0
-4 3 2 -3 2 1 0
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n;
while(~scanf("%d",&n),n)
{
int *a,i,j,k,temp;
a=(int *)calloc(n,sizeof(int));
for(i=0;i<n;i++)
{
scanf("%d",a+i);
}
for(i=1;i<n;i++)
{
if(abs(i[a])>abs((i-1)[a]))
{
temp=i[a];
(i)[a]=(i-1)[a];
for(j=i-2;j>=0&&abs(temp)>abs(j[a]);j--)
{
(j+1)[a]=(j)[a];
}
(j+1)[a]=temp;
}
}
for(i=0;i<n;i++)
{
printf(i==n-1?"%d\n":"%d ",i[a]);
}
}
return 0;
}