Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

What's wrong here?(Ambiguous Permutation Problem)

$
0
0

This is the problem I am attempting.(Ambiguous Permutation in easy section) I believe my code is ok . I know that I can make another array and compare but isn't that long? I'm new here, what am I missing? Thanks.

#include<iostream>

using namespace std;

int main()
{

    int n,flag;
    cin>>n;
    int a[100000];
    while(n!=0)
    {
           for(int y=0;y<n;y++)
           scanf("%d",&a[y]);
           flag=1;
           for(int i =0;i<n&&flag;i++)
           {
                int p = a[i];
                if((i+1)!= a[p-1])
                 flag--;
                }
                if(flag==1)
                cout<<"ambiguous";
                else if(flag==0)
                cout<<"not ambiguous";
                cin>>n;
                }

        return 0;        
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>