编译错误,求调
查看原帖
编译错误,求调
791222
lby_commandBlock楼主2024/4/21 09:45

错误信息

C:/Users/Administrator/AppData/Local/Temp/CP Editor-aaOHAu/sol.cpp:15:6: error: expected initializer before 'temp'
   15 | node temp(int fenzi, int fenmu) {
      |      ^~~~
C:/Users/Administrator/AppData/Local/Temp/CP Editor-aaOHAu/sol.cpp: In function 'int main()':
C:/Users/Administrator/AppData/Local/Temp/CP Editor-aaOHAu/sol.cpp:33:38: error: 'temp' was not declared in this scope; did you mean 'tm'?
   33 |                         vr.push_back(temp(j, i));
      |                                      ^~~~
      |                                      tm

错误代码

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

const int N = 1e5 + 9;

struct node {
	int fenzi, fenmu;
	double value;
	bool operator < (const node &a) const {
		return value < a.value;
	}
}

node temp(int fenzi, int fenmu) {
	node t;
	t.fenzi = fenzi;
	t.fenmu = fenmu;
	t.value = ((fenzi * 1.0) / (fenmu * 1.0)) * 1.0;
	return t;
}

vector<node> vr;

int n;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j < i; j++) {
			if (__gcd(i, j) != 1) continue;
			vr.push_back(temp(j, i));
		}
	}
	sort(vr.begin(), vr.end());
	for (auto &i : vr) {
		cout << i.fenmu << '/' << i.fenzi << endl;
	}
	return 0;
}
2024/4/21 09:45
加载中...