Пример массива.
- Details
-
Published on Friday, 31 May 2013 08:15
Пример программы обработки двухмерного массива.
extern void object::Solution( ) { errmode(0); int found [4][4]; point pos; for ( int x=0 ; x<4 ; x=x+1 ) { for ( int y=0 ; y<4 ; y=y+1 ) { // go to a platform pos.x = 10*x; pos.y = 10*y; goto(pos); // try to pick up an object grab(); if ( load == null ) { found[x][y] = 0; } else { // memorize item found found[x][y] = load.category; // put it down elsewhere move(-2); drop(Behind); } } }
// put objects back for ( int x=0 ; x<4 ; x=x+1 ) { for ( int y=0 ; y<4 ; y=y+1 ) { if ( found[y][x] == 0 ) continue; // go fetch object object item = radar(found[x][y]); goto(item.position); grab(); // put it on a platform // x and y are inverted pos.x = 10*y; pos.y = 10*x; goto(pos); drop(); } } }
|