在DEVC++上编译没问题,在洛谷上有问题,请大佬们看一看
查看原帖
在DEVC++上编译没问题,在洛谷上有问题,请大佬们看一看
775044
wkl20110514楼主2022/12/16 11:49

在DEVC++上编译没问题,在洛谷上有问题,请大佬们看一看

这是洛谷上的编译信息:

/tmp/compiler_gq7r_eah/src:13:8: 错误:‘double time’ redeclared as different kind of entity
   13 | double time=0;
      |        ^~~~
In file included from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/include-fixed/pthread.h:32,
                 from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/gthr-default.h:35,
                 from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/gthr.h:148,
                 from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/ext/atomicity.h:35,
                 from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/bits/ios_base.h:39,
                 from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/ios:42,
                 from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/ostream:38,
                 from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/iostream:39,
                 from /tmp/compiler_gq7r_eah/src:3:
/nix/store/7rfaw11na5ajdgwr55ffzwfibbrdpk8z-glibc-2.33-56-dev/include/time.h:75:15: 附注:previous declaration ‘time_t time(time_t*)’
   75 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
/tmp/compiler_gq7r_eah/src: 在函数‘int main()’中:
/tmp/compiler_gq7r_eah/src:24:28: 错误:操作数类型‘time_t(time_t*) noexcept’ {aka ‘long int(long int*)’}和‘double’对双目‘operator+’而言无效
   24 |   for(int j=0;j<i;j++) time+=a[j].num;
      |                        ~~~~^~~~~~~~~~
/tmp/compiler_gq7r_eah/src:24:35: 错误:在求‘operator+=(time_t(time_t*) noexcept {aka long int(long int*)}, double)’值时
   24 |   for(int j=0;j<i;j++) time+=a[j].num;
      |                                   ^~~
/tmp/compiler_gq7r_eah/src:26:24: 错误:操作数类型‘time_t(time_t*) noexcept’ {aka ‘long int(long int*)’}和‘int’对双目‘operator/’而言无效
   26 |  printf("\n%0.2lf",time/n);
      |                    ~~~~^~
      |                    |    |
      |                    |    int
      |                    time_t(time_t*) noexcept {aka long int(long int*)}

这是我的代码:

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
struct newint{
	double num;
	int number;
}a[1234];
bool cmp(newint x,newint y){
	return x.num<y.num;
}
double time=0;
int n;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf",&a[i].num);
		a[i].number=i+1;
	}
	sort(a,a+n,cmp);
	for(int i=0;i<n;i++){
		printf("%0.0lf ",a[i].num);
		for(int j=0;j<i;j++) time+=a[j].num;
	}
	printf("\n%0.2lf",time/n);
	return 0;
}

2022/12/16 11:49
加载中...