[求助] 线上编译错误
查看原帖
[求助] 线上编译错误
290596
Min_Zi_LRC楼主2021/7/27 15:54

本地编译成功,线上编译失败

代码

//https://www.luogu.com.cn/problem/P1223
#include <iostream>
#include <algorithm>
using namespace std;

int n, tmp, sumTime;

struct time {
	int order;
	int useTime;
} timeUsage[1001];

bool compare(time a, time b) {
	if (a.useTime == b.useTime) {
		return a.order < b.order;
	}
	return a.useTime < b.useTime;
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		timeUsage[i - 1].order = i;
		cin >> timeUsage[i - 1].useTime;
	}
	sort(timeUsage, timeUsage + n, compare);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			tmp += timeUsage[j].useTime;
		}
		sumTime += tmp;
		tmp = 0;
	}
	for (int i = 0; i < n; i++) {
		cout << timeUsage[i].order << ' ';
	}
	cout << endl << (double)sumTime / n;
	return 0;
}

日志


            /tmp/compiler_vlx_xo90/src:13:18: 错误:expected ‘)’ before ‘a’
 bool compare(time a, time b) {
             ~    ^~
                  )
/tmp/compiler_vlx_xo90/src:13:26: 错误:expected ‘)’ before ‘b’
 bool compare(time a, time b) {
             ~            ^~
                          )
/tmp/compiler_vlx_xo90/src:13:28: 错误:expression list treated as compound expression in initializer [-fpermissive]
 bool compare(time a, time b) {
                            ^
/tmp/compiler_vlx_xo90/src:13:28: 警告:left operand of comma operator is a reference, not call, to function ‘time’ [-Waddress]
/tmp/compiler_vlx_xo90/src:13:28: 警告:left operand of comma operator has no effect [-Wunused-value]
/tmp/compiler_vlx_xo90/src:13:28: 警告:‘time_t time(time_t*)’的地址永远不会为 NULL [-Waddress]
/tmp/compiler_vlx_xo90/src:13:30: 错误:expected ‘,’ or ‘;’ before ‘{’ token
 bool compare(time a, time b) {
                              ^
In file included from /usr/include/c++/8/bits/stl_algobase.h:71,
                 from /usr/include/c++/8/bits/char_traits.h:39,
                 from /usr/include/c++/8/ios:40,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from /tmp/compiler_vlx_xo90/src:2:
/usr/include/c++/8/bits/predefined_ops.h: In instantiation of ‘bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = time*; _Iterator2 = time*; _Compare = bool]’:
/usr/include/c++/8/bits/stl_algo.h:1847:14:   required from ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = time*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:1885:25:   required from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = time*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:1971:31:   required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = time*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:4866:18:   required from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = time*; _Compare = bool]’
/tmp/compiler_vlx_xo90/src:26:40:   required from here
/usr/include/c++/8/bits/predefined_ops.h:143:18: 错误:expression cannot be used as a function
         { return bool(_M_comp(*__it1, *__it2)); }
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/predefined_ops.h: In instantiation of ‘bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = time; _Iterator = time*; _Compare = bool]’:
/usr/include/c++/8/bits/stl_algo.h:1828:20:   required from ‘void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = time*; _Compare = __gnu_cxx::__ops::_Val_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:1855:36:   required from ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = time*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:1885:25:   required from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = time*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:1971:31:   required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = time*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:4866:18:   required from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = time*; _Compare = bool]’
/tmp/compiler_vlx_xo90/src:26:40:   required from here
/usr/include/c++/8/bits/predefined_ops.h:215:11: 错误:expression cannot be used as a function
  { return bool(_M_comp(__val, *__it)); }
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/predefined_ops.h: In instantiation of ‘bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = time*; _Value = time; _Compare = bool]’:
/usr/include/c++/8/bits/stl_heap.h:133:48:   required from ‘void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = time*; _Distance = long int; _Tp = time; _Compare = __gnu_cxx::__ops::_Iter_comp_val<bool>]’
/usr/include/c++/8/bits/stl_heap.h:237:23:   required from ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = time*; _Distance = long int; _Tp = time; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_heap.h:342:22:   required from ‘void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = time*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:1672:23:   required from ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = time*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:1933:25:   required from ‘void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = time*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:1948:27:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = time*; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:1968:25:   required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = time*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]’
/usr/include/c++/8/bits/stl_algo.h:4866:18:   required from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = time*; _Compare = bool]’
/tmp/compiler_vlx_xo90/src:26:40:   required from here
/usr/include/c++/8/bits/predefined_ops.h:177:11: 错误:expression cannot be used as a function
  { return bool(_M_comp(*__it, __val)); }
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
2021/7/27 15:54
加载中...