/ Randle /

记录详情

Compile Error

/in/foo.cc: In function 'int main()':
/in/foo.cc:37:2: error: 'sort' was not declared in this scope
  sort(v.begin(), v.end(), cmp);
  ^~~~
/in/foo.cc:37:2: note: suggested alternative: 'qsort'
  sort(v.begin(), v.end(), cmp);
  ^~~~
  qsort

代码

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;

int f[1005], g[1005], cnt[1005], n;

int cmp(int i, int j) {
	if (cnt[i] == cnt[j]) return (i < j);
	return cnt[i] < cnt[j];	
}

int main() {
	string s[1005];
	vector<int> v;

//	freopen("relations.in", "r", stdin);
//	freopen("relations.out", "w", stdout);

	cin >> n;

	for(int i=0; i<n; i++) {
		cin >> s[i];
		v.push_back(i);
		cnt[i] = 0;

		for(int j=0; j<n; j++) {
			if (s[i][j] == '1') {
				cnt[i]++;
			}
		}
	}

	sort(v.begin(), v.end(), cmp);
	bool correct = true;

	for(int i=0; i<n-1; i++) {
		int x = v[i];
		int y = v[i+1];

		for(int j=0; j<n; j++) 
			if (s[x][j] > s[y][j]) {
				correct = false;
				break;		
			}

		if(!correct) break;	
	}

	for(int i=0; i<n; i++) f[i] = n - cnt[i];
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) {
			if (s[i][j] == '1') g[j] = max(g[j], f[i]);
		}
	}

	if (correct) {
		cout << "YES" << endl;
		for(int i=0; i<n; i++) cout << f[i] << " ";
		cout << endl;
		for(int i=0; i<n; i++) cout << g[i] << " ";
		cout << endl;	
	} else {
		cout << "NO" << endl;
	}


}

信息

递交者
类型
递交
题目
关系 T3
题目数据
下载
语言
C++
递交时间
2017-10-06 20:11:40
评测时间
2017-10-06 20:11:40
评测机
分数
0
总耗时
454ms
峰值内存
36.613 MiB