HDOJ 2000-2010

 
 

2000 ASCII码排序

#include<stdio.h>

main(){
	
	char a,b,c,max,min,t;
	
	while(scanf("%c%c%c%c",&a,&b,&c,&t) != EOF){
		max = (a > b ? a : b ) > c ? ( a > b ? a : b ) : c;
		min = (a < b ? a : b ) < c ? ( a < b ? a : b ) : c;
		printf("%c %c %c\n",min,(a+b+c-max-min),max);
	}
}

2001 计算两点间的距离

#include<stdio.h>
#include<math.h>

main(){
	
	double x1,y1,x2,y2;
	double length;
	char t;
	
	while(scanf("%lf %lf %lf %lf%c",&x1,&y1,&x2,&y2,&t) != EOF){
		
		double temp = pow((x2-x1),2)+pow((y2-y1),2);
		length = sqrt(temp);
		printf("%.2lf\n",length);
		
	}
}

2002 计算球体积

#include<stdio.h>
#include<math.h>

#define PI 3.1415927

int main(){
	double r,v;
	char t;
	
	while(scanf("%lf%c",&r,&t) != EOF){
		v = (4.0/3) * PI * pow(r,3);
		printf("%.3lf\n",v);
	}
	return 0;
} 

2003 求绝对值

#include<stdio.h>
#include<math.h>

int main(){
	double a;
	char t;
	while(scanf("%lf%c",&a,&t) != EOF){
		printf("%.2lf\n",fabs(a));
	}
	return 0;
}

2004 成绩转换

#include<stdio.h>

int main(){
	int a;
	char t;
	while(scanf("%d%c",&a,&t) != EOF){
		if(a < 0 || a > 100){
			printf("Score is error!\n");
		}else{
			if(a>=0 && a<60){
				printf("E\n");
			}else if(a>=60 && a<70){
				printf("D\n");
			}else if(a>=70 && a<80){
				printf("C\n");
			}else if(a>=80 && a<90){
				printf("B\n");
			}else if(a>=90 && a<=100){
				printf("A\n");
			}
		}
		
	}
	return 0;
	 
}

2005 第几天?

#include<stdio.h>
int main(){
	int y,m,d;
	char t1,t2;
	int c[12]={31,28,31,30,31,30,31,31,30,31,30,31};
	while(scanf("%d%c%d%c%d",&y,&t1,&m,&t2,&d)!=EOF){
		int i;
		int no=0;
		for(i=0;i<m-1;i++){
			if(i==1){
				if((y%100!=0&&y%4==0)||(y%400==0)){
					no += 29;
				}else{
					no += 28;
				}
			}else{
				no += c[i];
			}
		}
		no += d;
		printf("%d\n",no);
	}
	return 0;
} 

2006 求奇数的乘积

#include<stdio.h>
int main(){
	int n,sum,t;
	while(scanf("%d",&n)!=EOF){
		sum=1;
		int i;
		for(i=0;i<n;i++){
			scanf("%d",&t);
			if(t%2!=0){
				sum *= t;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

2007 平方和与立方和

#include<stdio.h>
int main(){
	int m,n,x,y;
	while(scanf("%d %d",&m,&n)!=EOF){
		if(m>n){
			int t=m;m=n;n=t;
		}
		x = 0;y = 0;
		int i;
		for(i=m;i<=n;i++){
			if(i % 2 == 0){
				x += i*i;
			}else{
				y += i*i*i;
			}
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

2008 数值统计

#include<stdio.h>
int main(){
	int n, a,b,c;
	double t;
	while(scanf("%d",&n)!=EOF){
		if(n == 0){
			break;
		}
		a = b = c = 0;
		int i;
		for(i=0;i<n;i++){
			scanf("%lf",&t);
			if(t < 0){
				a ++;
			}else if(t == 0){
				b ++;
			}else{
				c ++;
			}
		}
		printf("%d %d %d\n",a,b,c);
	}
	return 0;
}

2009 求数列的和

#include<stdio.h>
#include<math.h>
int main(){
	int n,m;
	double sum;
	while(scanf("%d %d",&n,&m) != EOF){
		sum = n;
		double temp = n;
		int i;
		for(i = 0;i < m-1;i ++){
			temp = (double)sqrt(temp);
			sum += temp;		
		}
		printf("%.2lf\n",sum);
	}
	return 0;
}

2010 水仙花数

#include<stdio.h>
#include<math.h>
int main(){
	int m,n;
	while(scanf("%d %d",&m,&n)!=EOF){
		int no = 0;
		int i;
		for(i = m;i <= n;i ++){
			if(i == pow(i/100,3)+pow(i%100/10,3)+pow(i%10,3) ){
				if(no == 0){
					printf("%d",i);
				}else{
					printf(" %d",i);
				}
				no++;
			}
		}
		if(no == 0){
			printf("no\n");
		}else{
			printf("\n");	
		}
	}
	return 0;
} 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值