acm POJ1877,这个代码为什么C++能过G++不能过啊
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<fstrea...
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<fstream>
using namespace std;
#define LEN 1000
//#define cin fin
//ifstream cin("1.txt");
int main (void)
{
int n,m,start,maxn,num,sum,i;
int region[LEN];
double water,remain;
num=1;
while(cin>>n>>m&&(n||m)){
for(i=0;i<n*m;i++)
cin>>region[i];
cin>>maxn;
sort(region,region+n*m);
start=region[0];
sum=0;
for(i=1;i<n*m;i++)
if(sum+(region[i]-start)*i*100<=maxn){
sum+=(region[i]-start)*i*100;
start=region[i];
}
else
break;
remain=maxn-sum;
water=region[i-1]+remain/(double(i)*100.0);
for(i=0;region[i]<water&&i<n*m;i++);
printf("Region %d\n",num++);
printf("Water level is %.2f meters.\n",water);
printf("%.2f percent of the region is under water.\n\n",100*i/double(n*m));
}
return 0;
} 展开
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<fstream>
using namespace std;
#define LEN 1000
//#define cin fin
//ifstream cin("1.txt");
int main (void)
{
int n,m,start,maxn,num,sum,i;
int region[LEN];
double water,remain;
num=1;
while(cin>>n>>m&&(n||m)){
for(i=0;i<n*m;i++)
cin>>region[i];
cin>>maxn;
sort(region,region+n*m);
start=region[0];
sum=0;
for(i=1;i<n*m;i++)
if(sum+(region[i]-start)*i*100<=maxn){
sum+=(region[i]-start)*i*100;
start=region[i];
}
else
break;
remain=maxn-sum;
water=region[i-1]+remain/(double(i)*100.0);
for(i=0;region[i]<water&&i<n*m;i++);
printf("Region %d\n",num++);
printf("Water level is %.2f meters.\n",water);
printf("%.2f percent of the region is under water.\n\n",100*i/double(n*m));
}
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询