杭电oj2000-2009————C语言

2000ASCII码排序
http://acm.hdu.edu.cn/showproblem.php?pid=2000

#include 
int main()
{
char a,b,c,t;
while(~scanf("%c%c%c",&a,&b,&c))
{
getchar();
if(a>b) {t=a;a=b;b=t;}
if(a>c) {t=a;a=c;c=t;}
if(b>c) {t=b;b=c;c=t;}
printf("%c %c %c\n",a,b,c);
}
return 0;
}

2001计算两点间的距离
http://acm.hdu.edu.cn/showproblem.php?pid=2001

#include 
#include 
#include 
int main()
{
float x1,x2,y1,y2,s;
while(~scanf("%f%f%f%f",&x1,&y1,&x2,&y2))
{
s=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
printf("%.2f\n",s);
}
return 0;
}

2002计算球的体积
http://acm.hdu.edu.cn/showproblem.php?pid=2002

#include
#include
#define PI 3.1415927
int main()
{
    double r;
    while(scanf("%lf",&r) != EOF)
    {
        printf("%.3lf\n",PI * pow(r,3) * 4 / 3);
    }
    return 0;
}

2003求绝对值
http://acm.hdu.edu.cn/showproblem.php?pid=2003

#include 
#include 
int main()
{
double a;
while(~scanf("%lf",&a)){
	printf("%.2lf\n",fabs(a));
}
return 0;
}

2004成绩转换

http://acm.hdu.edu.cn/showproblem.php?pid=2004

#include 
int main()
{
int i;
while(~scanf("%d",&i))
{
if(i>=90&&i<=100) {printf("A\n");}
else if(i>=80&&i<=89) {printf("B\n");}
else if(i>=70&&i<=79) {printf("C\n");}
else if(i>=60&&i<=69) {printf("D\n");}
else if(i>=0&&i<=59) {printf("E\n");}
else printf("Score is error!\n");
}
return 0;
}

2005第几天?

http://acm.hdu.edu.cn/showproblem.php?pid=2005

#include 
int main()
{
int a[12]={31,0,31,30,31,30,31,31,30,31,30,31};
int year,month,day;
int total=0;
while(~scanf("%d/%d/%d",&year,&month,&day))
{
	if((year%4==0)&&(year%100!=0)||(year%400==0))//闰年
		{a[1]=29;}
	else
		{a[1]=28;}
	for(int i=0;i<month-1;i++)
		{total+=a[i];}//除了最后一个月天数和
	
	total += day;//加上最后一个月天数
	printf("%d\n",total);
	total = 0;
}
return 0;
}

2006求奇数的乘积

http://acm.hdu.edu.cn/showproblem.php?pid=2006

#include
int main(){
    int n,m,a;
    while(~scanf("%d",&n)){
        m=1;
        while(n--){
            scanf("%d",&a);
            if(a%2!=0)
                m=m*a;
        }
        printf("%d\n",m);
    }
    return 0;
}

2007平方和与立方和

http://acm.hdu.edu.cn/showproblem.php?pid=2007


#include 
int main()
{
int m,n,x,y;
while(~scanf("%d%d",&m,&n))
{
    x=0;y=0;
    int t;
    if (m > n) {t = m; m = n; n = t;}//判断m,n的大小
	for(;m <= n; m++) 
	{
		if(m %2 == 0) {x += m*m;} 
		else {y += m*m*m;}
	}
	printf("%d %d\n",x,y);
}
return 0;
}

2008数值统计

http://acm.hdu.edu.cn/showproblem.php?pid=2008

#include 
int main()
{
	float n,i,a,b,c;
	while(~scanf("%f",&n)&&n!=0)
	{
    	a=0;b=0;c=0;
		while(n--)
		{
			scanf("%f",&i);
			if(i==0) {b=b+1;}
			if(i>0)  {c=c+1;}
            if(i<0)  {a=a+1;}
		}
	printf("%.0f %.0f %.0f\n",a,b,c);
}
return 0;
}

2009求数列的和

http://acm.hdu.edu.cn/showproblem.php?pid=2009

#include 
#include 
int main()
{
	float n,m,sum;
	while(~scanf("%f%f",&n,&m))
	{
		sum=0;
		for(int i=0;i<m;i++)
		{
		sum+=n;
		n=sqrt(n);
		}
		printf("%.2f\n",sum);
	}
return 0;
}

你可能感兴趣的:(杭电oj2000-2009————C语言)