SPOJ- Ambiguous Permutations Problem Solution
Solution:-
using namespace std;
#define MAX 100010
int arr[MAX];
bool cal_per(int n)
{
for(int i=1;i<=n;i++)
{
if(i!=arr[arr[i]])
return false;
}
return true;
}
int main()
{
int n;
while(1)
{
cin>>n;
if(n==0)
break;
for(int i=1;i<=n;i++)
cin>>arr[i];
if(cal_per(n))
cout<<"ambiguous\n";
else
cout<<"not ambiguous\n";
}
return 0;
}
No comments:
Post a Comment