/*
Copyright 2011 Marek "p2004a" Rusinowski
Binary search
*/
#include <cstdio>
#define MAXN 1000000
int array[ MAXN] ;
int pos( int * begin, int * end, int a) {
int * old_begin = begin, * center = NULL ;
while ( begin + 1 < end) {
center = ( end - begin) / 2 + begin;
if ( * center < a) {
begin = center;
} else if ( * center > a) {
end = center;
} else {
return center - old_begin;
}
}
return begin - old_begin;
}
int main( ) {
int n, a;
scanf ( "%d" , & n) ;
for ( int i = 0 ; i < n; ++ i) {
scanf ( "%d" , & array[ i] ) ;
}
scanf ( "%d" , & a) ;
printf ( "%d\n " , pos( array, array + n, a) + 1 ) ;
return 0 ;
}
LyoKICBDb3B5cmlnaHQgMjAxMSBNYXJlayAicDIwMDRhIiBSdXNpbm93c2tpCiAgQmluYXJ5IHNlYXJjaAoqLwojaW5jbHVkZSA8Y3N0ZGlvPgoKI2RlZmluZSBNQVhOIDEwMDAwMDAKCmludCBhcnJheVtNQVhOXTsKCmludCBwb3MoaW50ICpiZWdpbiwgaW50ICplbmQsIGludCBhKSB7CiAgaW50ICpvbGRfYmVnaW4gPSBiZWdpbiwgKmNlbnRlciA9IE5VTEw7CiAgd2hpbGUgKGJlZ2luICsgMSA8IGVuZCkgewogICAgY2VudGVyID0gKGVuZCAtIGJlZ2luKSAvIDIgKyBiZWdpbjsKICAgIGlmICgqY2VudGVyIDwgYSkgewogICAgICBiZWdpbiA9IGNlbnRlcjsKICAgIH0gZWxzZSBpZiAoKmNlbnRlciA+IGEpIHsKICAgICAgZW5kID0gY2VudGVyOwogICAgfSBlbHNlIHsKICAgICAgcmV0dXJuIGNlbnRlciAtIG9sZF9iZWdpbjsKICAgIH0KICB9CiAgcmV0dXJuIGJlZ2luIC0gb2xkX2JlZ2luOwp9CgppbnQgbWFpbigpIHsKICBpbnQgbiwgYTsKICBzY2FuZigiJWQiLCAmbik7CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgIHNjYW5mKCIlZCIsICZhcnJheVtpXSk7CiAgfQogIHNjYW5mKCIlZCIsICZhKTsKICBwcmludGYoIiVkXG4iLCBwb3MoYXJyYXksIGFycmF5ICsgbiwgYSkgKyAxKTsKICByZXR1cm4gMDsKfQo=
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout