问题:
Input several one blank separated integers, output the maximum, minimum and average (with %.2f format) of all positive integers separated by a space in one line and those of all negative integers in next line.
输入格式:
There are no more than 106 integers. Every one of them can be stored in a signed 32-bit integer. It is guaranteed that there is at least one positive integer and at least one negative integer.
我写的代码:
using namespace std;
int main()
{
int n,c1=0,c2=0;
long long int sum1=0,sum2=0;
double av1,av2,max1=0,max2=-1.7e+308,min1=1.7e+308,min2=0;
while(1)
{
scanf("%d",&n);
char c=getchar();
if(n>0)
{
sum1+=n;
c1++;
if(n>max1)max1=n;
if(n<min1)min1=n;
}
else
{
sum2+=n;
c2++;
if(n>max2)max2=n;
if(n<min2)min2=n;
}
if(c=='\n')break;
}
av1=1.0sum1/c1;
av2=1.0sum2/c2;
printf("%.2f %.2f %.2f\n",max1,min1,av1);
printf("%.2f %.2f %.2f\n",max2,min2,av2);
return 0;
}
10个数据点过了9个,不知道为什么,求助大家,谢谢