Monday, November 13, 2017

Ambiguous Permutations Codechef Problem Solution


https://www.codechef.com/problems/PERMUT2

In C++...................


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while (n!=0)
    {
        bool flag= true;
        int a[n+1] , i;
        for ( i = 1 ; i <= n ; i++ )
        cin>> a[i];
        for (i=1; i<=n ;i++)
        {
            if (a[a[i]] != i )
            flag= false;
        }
        if (flag)
        cout<<"ambiguous\n";
        else
        cout<<"not ambiguous\n";
       
        cin>>n;
    }
    return 0;
}

No comments:

Post a Comment