Ambiguous Permutations

//http://www.spoj.com/problems/PERMUT2/
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
	int buffer[100001];
	int n;
	cin >> n;
	while (n!=0) {
		for (int i = 1; i <=n; i++) {
			cin >> buffer[i];
		}
		int notambiguous = true;
		for (int i = 1; i <=n; i++) {
			if (buffer[buffer[i]] != i) {
				notambiguous = false;
			}
		}
		if (notambiguous) {
			cout << "ambiguous" << endl;
		} else {
			cout << "not ambiguous" << endl;
		}
		cin >> n;
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章