-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.c
67 lines (67 loc) · 1.12 KB
/
C.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<stdio.h>
int main()
{
int x,n,p[101],y,z,a,b,i,j,swap,q=0,s;
scanf("%d%d",&x,&n);
for(i=0;i<n;i++)
{
scanf("%d",&p[i]);
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(p[j]>p[j+1])
{
swap=p[j];
p[j]=p[j+1];
p[j+1]=swap;
}
}
}
for(i=0;;i++)
{
if(p[i]==x)
{
q=1;
s=i;
break;
}
else if(i==n)
{
break;
}
}
y=x+1;
z=x;
if(q==0)
printf("%d",x);
else
{
for(i=s+1;i<n;i++)
{
if(p[i]>y)
break;
else if(p[i]==y)
y++;
else
continue;
}
for(i=s;i>=0;i--)
{
if(p[i]<z)
break;
else if(p[i]==z)
z--;
else
continue;
}
a=y-x;
b=x-z;
if(a<b)
printf("%d",y);
else
printf("%d",z);
}
return 0;
}