WRONG ANSWER IN AMBIGUOUS PERMUTATIONS

#include<stdio.h>
int main()
{
int nod,copy=0,num,pnum=0,pos=0,a=0;
scanf("%d %d",&nod,&num);
for(int i=1;i<=nod;i++)
{
pos=0;
copy=num;
while(copy!=0)
{
pos+=1;
a=copy%10;
if(i==a)
pnum=pnum*10+(nod-pos+1);
copy=copy/10;
}
}
if(pnum==num)
printf(“ambiguous”);
else
printf(“not ambiguous”);
printf("\n");
}

Please a) format your code (copying and posting it as-is gives code that doesn’t compile) and b) link to the problem so we don’t have to google it :slight_smile:

The first problem seems to be that you aren’t handling multiple testcases - the example input

4
1 4 3 2
5
2 3 4 5 1
1
1
0

should print out 3 different values:

ambiguous
not ambiguous
ambiguous

but yours only prints one.

I recommend that you get in the habit of running your program with the example input locally, and not submitting until (at least) that gives the correct answer :slight_smile:

Edit:

Once you’ve got the example input working, try this testcase where N is always 15

Testcase (N = 15)
15
15 4 13 2 9 11 8 7 5 10 6 14 3 12 1 
15
11 13 4 12 7 6 2 5 15 10 9 8 14 1 3 
15
11 4 13 14 5 6 8 9 10 3 12 15 2 1 7 
15
4 11 9 1 6 5 12 13 3 14 2 7 8 10 15 
15
15 10 6 14 12 2 13 9 5 3 11 8 4 7 1 
15
14 9 13 15 8 10 12 5 2 6 11 7 3 1 4 
15
14 8 11 5 4 15 12 2 10 9 3 7 13 1 6 
15
15 10 7 3 4 13 12 2 8 14 5 6 1 11 9 
15
5 6 8 7 1 2 4 3 15 10 12 11 14 13 9 
15
5 12 6 4 1 3 9 15 7 11 10 2 14 13 8 
15
6 8 14 3 11 1 9 2 15 7 13 12 4 5 10 
15
1 10 6 13 12 3 9 15 7 2 14 5 4 11 8 
15
9 7 5 2 12 15 13 10 11 3 8 6 4 14 1 
15
11 10 7 14 13 9 3 15 6 2 1 12 5 4 8 
15
9 14 6 3 1 13 11 4 15 5 8 12 10 2 7 
15
12 7 15 14 10 8 2 6 11 5 9 1 13 4 3 
15
13 3 2 6 8 4 9 5 7 15 11 14 1 12 10 
15
13 5 8 4 2 12 11 3 14 15 7 6 1 9 10 
15
10 3 2 14 8 13 7 5 15 1 12 11 6 4 9 
15
12 7 13 10 11 6 2 14 15 4 5 1 3 8 9 
0

The results for this should be:

Testcase (N = 15) Answers
ambiguous
not ambiguous
not ambiguous
ambiguous
not ambiguous
ambiguous
ambiguous
not ambiguous
ambiguous
ambiguous
not ambiguous
ambiguous
not ambiguous
ambiguous
not ambiguous
ambiguous
ambiguous
ambiguous
ambiguous
ambiguous
1 Like