OJ2002题、2003题、2004题、2005题、2006题

Problem Description
根据输入的半径值,计算球的体积。

Input
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。

Output
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。

Sample Input
   
   
1 1.5

Sample Output
   
   
4.189 14.137
#include <stdio.h>
#include <math.h>
#define PI 3.1415927

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


求实数的绝对值。

Input
输入数据有多组,每组占一行,每行包含一个实数。

Output
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。

Sample Input
   
   
123 -234.00

Sample Output
   
   
123.00 234.00
#include <stdio.h>
#include <math.h>

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

Problem Description
输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;

Input
输入数据有多组,每组占一行,由一个整数组成。

Output
对于每组输入数据,输出一行。如果输入数据不在0~100范围内,请输出一行:“Score is error!”。

Sample Input
   
   
56 67 100 123

Sample Output
   
   
E D A Score is error!
#include <stdio.h>

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

给定一个日期,输出这个日期是该年的第几天。

Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。

Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。

Sample Input
   
   
1985/1/20 2006/3/12

Sample Output
   
   
20 71
#include <stdio.h>

void main() 
{
	int y,m,d,i;
	int sum[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	while(scanf("%d/%d/%d",&y,&m,&d)!=EOF)
	{
		int j=0;
		int a=0;
		if(m>2&&m<=12)
			a=1;
		for(i=0;i<m;i++)
		{
			j=j+sum[i];	
		}
		if((y%4==0&&y%100!=0)||y%400==0)
		{		
				printf("%d\n",j+d+a);	
		}
		else
			printf("%d\n",j+d);	
	}
}
给你n个整数,求他们中所有奇数的乘积。

Input
输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数,你可以假设每组数据必定至少存在一个奇数。

Output
输出每组数中的所有奇数的乘积,对于测试实例,输出一行。

Sample Input
   
   
3 1 2 3 4 2 3 4 5

Sample Output
   
   
3 15
#include <stdio.h>

int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int s=1;
		int x,i;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&x);
			if(x%2)
				s*=x;
		}
		printf("%d\n",s);
	}
	return 0;
}




  
  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值