A - ASCII码排序
http://acm.hdu.edu.cn/showproblem.php?pid=2000
qwe asd zxcSample Output
e q w a d s c x z
#include
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;
}
http://acm.hdu.edu.cn/showproblem.php?pid=2001
0 0 0 1 0 1 1 0Sample Output
1.00 1.41
#include
#include
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;
}
http://acm.hdu.edu.cn/showproblem.php?pid=2002
1 1.5Sample Output
4.189
14.137
Hint
#define PI 3.1415927
#include
#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;
}
http://acm.hdu.edu.cn/showproblem.php?pid=2003
#include
#include
int main()
{
double x;
while(~scanf("%lf",&x))
{
printf("%.2lf\n",fabs(x));
}
return 0;
}
http://acm.hdu.edu.cn/showproblem.php?pid=2004
#include
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;
}
http://acm.hdu.edu.cn/showproblem.php?pid=2005
#include
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;
}
http://acm.hdu.edu.cn/showproblem.php?pid=2006
#include
int main()
{
int n,x;
while(~scanf("%d",&n))
{
int i,ans=1;
for(i=0;i
http://acm.hdu.edu.cn/showproblem.php?pid=2007
#include
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 - 数值统计
#include
int main()
{
int n;
while(~scanf("%d",&n),n)
{
int i,zero=0,plus=0,negative=0;
double x;
for(i=0;i
http://acm.hdu.edu.cn/showproblem.php?pid=2010
#include
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
http://acm.hdu.edu.cn/showproblem.php?pid=2011
#include
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
#include
#include
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
http://acm.hdu.edu.cn/showproblem.php?pid=2013
#include
#include
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
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;
}
http://acm.hdu.edu.cn/showproblem.php?pid=2014
#include
#include
#include
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
P - 偶数求和
http://acm.hdu.edu.cn/showproblem.php?pid=2015
#include
#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;
}
http://acm.hdu.edu.cn/showproblem.php?pid=2016
#include
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=a[i])
{
min=a[i];
j=i;
}
}
temp=a[0];
a[0]=a[j];
a[j]=temp;
for(i=0;i
http://acm.hdu.edu.cn/showproblem.php?pid=2017
#include
#include
#include
int main()
{
char a[1000];
int i,len,n,count;
scanf("%d",&n);
while(n--)
{
count=0;
scanf("%s",a);
for(i=0;i
http://acm.hdu.edu.cn/showproblem.php?pid=2018
#include
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;
}
http://acm.hdu.edu.cn/showproblem.php?pid=2019
#include
#include
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=m&&flag==-1)
{
flag=i;
}
}
for(i=0;i
U - 绝对值排序
http://acm.hdu.edu.cn/showproblem.php?pid=2020
#include
#include
int main()
{
int n;
while(~scanf("%d",&n),n)
{
int *a,i,j,k,temp;
a=(int *)calloc(n,sizeof(int));
for(i=0;iabs((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