首页 新闻 会员 周边

OJ菜鸟求助

0
[已关闭问题] 关闭于 2019-03-24 22:59

问题:
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.
我写的代码:

include<iostream>

include<stdio.h>

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.0
sum2/c2;
printf("%.2f %.2f %.2f\n",max1,min1,av1);
printf("%.2f %.2f %.2f\n",max2,min2,av2);
return 0;
}

10个数据点过了9个,不知道为什么,求助大家,谢谢

MissCold的主页 MissCold | 菜鸟二级 | 园豆:204
提问于:2019-03-08 18:40
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册