, . . .
1) , (). , , , .
2) , . .
3) , . (, ) , ..
4) , . - . .
- ( ), ( , .. ). , (, ..) , .
() , , . . , . ( ) ( ).
, . .
, , , .
. . :
a) ,
b)
c) .
. , .
. , , . , .
|
|
, , .
.
1. ().
2.
.
3. .
, ( ) ( ).
:
1) ;
2) :
3) .
1.1.
. , , , ( ).
.
1. ().
2.
2. 1. ( );
2. 2. ,
2.2.1. ( , num) = - 1 ( , );
2.2.2. (i) 0 .
= [ i ],
(num) = i;
2.2.3. num = - 1,
: ,
: num.
.
3. .
key, - arg. , .
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n;
System.out.print(" => ");
n=sc.nextInt();
System.out.println("\t ");
int key[]=new int[n];
for (int i = 0; i < key.length;i++)
key[i]=sc.nextInt();
System.out.println("\n ");
do{
int arg,num;
System.out.println("\n ");
arg=sc.nextInt();
if (arg>=0){
num=-1;
for (int i = 0; i < key.length; i++)
if (arg==key [i])
num=i;
if (num ==-1)
System.out.println(" ");
else
System.out.println(" + num);
} while (arg>=0);
}
. For n , , . , , , .. . , , . () n / 2.
, 2 .