2232 - 多输入输出练习1

给定很多行数据,要求输出每一行的最大值.

题目输入

程序有多行输入,每一行以0结束.

题目输出

有多行输出,对应输入的行数.

输入/输出样例

题目输入

23 -456 33 78 0
43 23 987 66 -137 324 0
544 27 7 9 102 234 -44 -732 723 0

题目输出

78
987
723

C语言解答

#include<stdio.h>

int main()
{
	int tmp=1,max=0;
	while(scanf("%d",&tmp)!=EOF)
	{
		
		if(tmp>max)
		{
			max=tmp;		
		}
		if(tmp==0)
		{
			printf("%d\n",max);
			max=0; 
		}
	}
	return 0;
}

C++解答

#include<stdio.h>
int max(int a,int b)
{
	return a>b?a:b;
}
int main()
{
	int maxnum=0,temp;
	while(scanf("%d",&temp)!=EOF)
	{
		maxnum=temp;
		while(scanf("%d",&temp)!=EOF&&temp)
		{
			maxnum=max(maxnum,temp);
		}
		printf("%d\n",maxnum);
	}
	return 0;
}
时间限制 1 秒
内存限制 128 MB
讨论 统计
上一题 下一题