周报-寒假2

oj输入格式

题干

Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2

代码

#include

int main()
{
     
	int a, b;
	while (scanf("%d%d", &a, &b) != EOF)
	{
     
		printf("%d\n", a + b);
	}
	return 0;
}

ASCII码排序

题干

输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
Sample Input
qwe
asd
zxc
Sample Output
e q w
a d s
c x z

代码

# include

int main()
{
     
	char world[4];
	while(scanf("%s",world)!=EOF)
	{
     
		char a=world[0],b=world[1],c=world[2];
		char t;
		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;
}

第几天

题干

给定一个日期,输出这个日期是该年的第几天。
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
Sample Input
1985/1/20
2006/3/12
Sample Output
20
71

代码

# include

int main()
{
     
	int y,m,d;
	while(scanf("%d/%d/%d",&y,&m,&d)!=EOF)
	{
     
		int a[12]={
     31,28,31,30,31,30,31,31,30,31,30,31};
		int b[12]={
     31,29,31,30,31,30,31,31,30,31,30,31};
		int day;
		if(y%4==0 && y%100!=0 || y%400==0){
     
			day=0;
			int i=0;
			for(i=0;i<m-1;i++){
     
				day+=b[i];
			}
			day+=d;
		}
		else{
     
			day=0;
			int i=0;
			for(i=0;i<m-1;i++){
     
				day+=a[i];
			}
			day+=d;
		}
		printf("%d\n",day);
	}
	return 0;
}

求整数的乘积

题干

给你n个整数,求他们中所有奇数的乘积。
Input
输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数,你可以假设每组数据必定至少存在一个奇数。
Output
输出每组数中的所有奇数的乘积,对于测试实例,输出一行。
Sample Input
3 1 2 3
4 2 3 4 5
Sample Output
3
15

代码

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

数值统计

题干

统计给定的n个数中,负数、零和正数的个数。
Input
输入数据有多组,每组占一行,每行的第一个数是整数n(n<100),表示需要统计的数值的个数,然后是n个实数;如果n=0,则表示输入结束,该行不做处理。
Output
对于每组输入数据,输出一行a,b和c,分别表示给定的数据中负数、零和正数的个数。
Sample Input
6 0 1 2 3 -1 0
5 1 2 3 4 0.5
0
Sample Output
1 2 3
0 0 5

代码

#include
int main()
{
     
    double b;
    int i=0,a;
    while((scanf("%d",&a))!=EOF)
    {
     
    	int z=0,f=0,l=0;
    	for(i=0;i<a;i++){
     
    	scanf("%lf",&b);
		if(b>0){
     
			z++;
		}
		else if(b<0){
     
			f++;
		}
		else{
     
			l++;
		}
		}
    	if(a!=0){
     
    		printf("%d %d %d\n",f,l,z);
		}
    }
    return 0;
}

你可能感兴趣的:(周报-寒假2)