CÓïÑÔµÄÒ»¸ö¼òµ¥Ëã·¨: 26¸ö×ÖÄ¸Ëæ»ú²½Éú³É
Ò»¸ö¼òµ¥µÄС³ÌÐò, ÔÌâÄ¿¼û<CÓïÑÔ³ÌÐòÉè¼Æ-ÏÖ´ú·½·¨>µÚ°ËÕÂÁ·Ï°13.
ÓÉÓÚ×Ô¼ºÖ»¿´µ½µÚ°ËÕÂ, ËùÒÔ, ²»¸ÒóȻʹÓú¯ÊýµÈÆäËûÄÚÈÝ, ¸ßÊÖÇë·ÅÉù´óЦ.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define ROWS 10
#define COLS 10
/**
* @author: selfimpr
* @blog: http://blog.csdn.net/lgg201
* @email: lgg860911@yahoo.com.cn
* ¹¦ÄÜ:
* ROWS * COLSµÄ·½¸ñÖÐʵÏÖËæ»ú²½. ¼´½«26¸ö´óд×Öĸ°´Ë³ÐòÒÔËæ»úµÄ·½ÏòÅÅÁÐ.
* ÕâÀïʵÏÖµÄÊǰ˸ö·½Ïò(º¹, ²»ÖªµÀÓÐûÓа˸ö·½Ïòһ˵.)
* ȱÏÝ:
* Óнϴó¼¸Âʱ»À§ËÀ, ûÓÐ×öÓÅ»¯´¦Àí.
* Êý¾Ý½á¹¹Éè¼Æ:
* 1. ROWS, COLSºê¶¨ÒåÁËÆåÅ̵ĴóС
* 2. board¶þάÊý×鶨ÒåÁËÆåÅÌ, ûÓÐ×ÖĸµÄÒÔ.ºÅ²¹¿Õ
* 3. i, jΪѻ·Òò×Ó, ÔÚ·½Ïò¿ØÖÆÊ±, ³äµ±ÁËÒÆ¶¯µÄ·½Ïò¿ØÖÆ.
* 4. directionΪ·½Ïò¿ØÖƱäÁ¿.
* 5. chÊÇ˳Ðò»ñÈ¡×ÖĸµÄÑ»·Òò×Ó.
* 6. row, col´æ´¢ÁÙʱµÄÒÆ¶¯×ø±ê, ´æ´¢¸Ã×ø±êΪÁ˱£Ö¤»ñÈ¡µÄ·½Ïò²»¿ÉÓÃʱ, ²»Ó°ÏìÔÊý¾Ý.
* Á÷³Ì:
* 1. ³õʼ»¯ÆåÅÌ, ÒÔ.ºÅ³õʼ»¯ËùÓÐÔªËØ, ´òÓ¡Ò»´Î¿ÕÆåÅ̺ó, ½«ÆåÅÌ[0, 0]×ø±êÔªËØÉèÖÃΪ'A'.
* 2. ÉèÖÃËæ»úÊýÉú³ÉÖÖ×ÓΪµ±Ç°Ê±¼ä, ÒÔ±£Ö¤Ã¿´ÎÉú³ÉµÄËæ»úÊý²»Í¬.
* 2. Ñ»·´¦Àí×Öĸ
* 3. »ñÈ¡Ëæ»ú·½Ïò, ²¢¸ù¾Ý·½ÏòÈ¡µÃÒÆ¶¯ºóµÄ×ø±ê, ±£´æµ½ÁÙʱ±äÁ¿rowºÍcolÖÐ.
* 4. ÅжÏеÄ×ø±êÊÇ·ñÓÐЧ
* 5. Èç¹ûÐÂ×ø±ê²»¿ÉÓÃ, µ½µÚ3²½ÖØÐ»ñÈ¡·½Ïò.
* 6. Èç¹ûÐÂ×ø±êÓÐЧ:
* 6.1. ÉèÖÃÆåÅ̶ÔӦλÖõÄ×Öĸ
* 6.2. ½«ÁÙÊ±×ø±êÐÅϢת´æµ½ÕæÕýµÄµ±Ç°×ø±êi, jÖÐ.
* 6.3. »ñÈ¡ÏÂÒ»¸ö×Öĸ
* 6.4. µ½µÚ2²½ÖØÐ¿ªÊ¼´¦ÀíÏÂÒ»¸ö×Öĸ.
* 7. ´òÓ¡×îºóÉú³ÉµÄÆåÅÌ.
*
*/
int main() {
char board[ROWS][COLS];
int i, j, direction;
srand( (unsigned) time(NULL));
for(i = 0; i < ROWS; i ++) {
for(j = 0; j < COLS; j ++) {
board[i][j] = '.';
}
}
for(i = 0; i < ROWS; i ++) {
for(j = 0; j < COLS; j ++) {
printf("%c ", board[i][j]);
}
printf("\n");
}
board[0][0] = 'A';
printf("\n");
char ch;
i = 0; j = 0;
int row = 0, col = 0;
for(ch = 'B'; ch <= 'Z';) {
direction = rand() % 8;
switch(directio
Ïà¹ØÎĵµ£º
×ªÔØ×Ô£º
ܰÈÙ¼ÒÔ°blog
ÔÚCÓïÑÔÖУ¬¼ÙÉèÎÒÃÇÓÐÕâÑùµÄÒ»¸öº¯Êý£º
int function(int a,int b)
µ÷
ÓÃʱֻҪÓÃresult =
function(1,2)ÕâÑùµÄ·½Ê½¾Í¿ÉÒÔʹÓÃÕâ¸öº¯Êý¡£µ«ÊÇ£¬µ±¸ß¼¶ÓïÑÔ±»±àÒë³É¼ÆËã»ú¿ÉÒÔʶ±ðµÄ»úÆ÷Âëʱ£¬ÓÐÒ»¸öÎÊÌâ¾Í͹ÏÖ³öÀ´£ºÔÚCPUÖУ¬¼ÆËã
»úûÓа취֪µÀÒ»¸öº¯Êýµ÷ÓÃÐèÒª¶àÉÙ¸ö¡¢Ê²Ã´ÑùµÄ²ÎÊý£¬Ò² ......
rows="2" cols="20" id="ctl00_ctl00_cphContent_cphDoc_EntryEditor1_richTextEditor" class="mceEditor" style="height:450px;width:100%;">
Õ»ÊÇÊý¾Ý½á¹¹ÖÐ×î»ù´¡Ò²ÊÇ×î¾µäµÄÊý¾Ý½á¹¹£¬ÎÞÂÛÔÚÓ¦Óû¹ÊDzÙ×÷ϵͳÖоù¿ÉÒÔ¿´µ½ÆäÉíÓ°¡£Õ»ÊÇÒ»ÖÖÌØÊâµÄ
ÏßÐÔ±í£¬¼´ÏÞÖÆÔÚ±íµÄÒ»¶Ë½øÐвåÈ롢ɾ³ýÔËË㡣ͨ³£²åÈ롢ɾ³ýµÄÒ»¶Ë³ ......
Ò»¡¢´ÓCÓëC++±àÒëÁ¬½Ó·½Ê½ÉîÈëÀí½âextern "C"
<1>.CºÍC++¶Ôº¯ÊýµÄ´¦Àí·½Ê½ÊDz»Í¬µÄ.±»extern "C"ÐÞÊεıäÁ¿ºÍº¯ÊýÊǰ´ÕÕCÓïÑÔ·½Ê½±àÒëºÍÁ¬½ÓµÄ.extern "C"ÓÃÓÚʵÏÖC++ÓëC¼°ÆäËüÓïÑԵĻìºÏ±à³Ì¡£
<2>.δ¼Óextern “C”ÉùÃ÷ʱµÄ±àÒ뷽ʽ
Ê×ÏÈ¿´¿´C++ÖжÔÀàËÆCµÄº¯ÊýÊÇÔõÑù±àÒëµÄ¡£
×÷ΪһÖÖÃæÏò ......
¡¡¡¡1£¬mallocÓëfreeÊÇC++/CÓïÑԵıê×¼¿âº¯Êý£¬new/deleteÊÇC++µÄÔËËã·û¡£ËüÃǶ¼¿ÉÓÃÓÚÉêÇ붯̬ÄÚ´æºÍÊÍ·ÅÄÚ´æ¡£
¡¡¡¡2£¬¶ÔÓÚ·ÇÄÚ²¿Êý¾ÝÀàÐ͵ĶÔÏó¶øÑÔ£¬¹âÓÃmaloc/freeÎÞ·¨Âú×㶯̬¶ÔÏóµÄÒªÇó¡£¶ÔÏóÔÚ´´½¨µÄͬʱҪ×Ô¶¯Ö´Ðй¹Ô캯Êý£¬¶ÔÏóÔÚÏûÍö֮ǰҪ×Ô¶¯Ö´ÐÐÎö¹¹º¯Êý¡£ÓÉÓÚmalloc/freeÊǿ⺯Êý¶ø²»ÊÇÔËËã·û£¬²»ÔÚ±àÒëÆ ......
»ã±à½ÒÃØCÓïÑÔÖеIJÎÊý´«µÝÎÊÌâ[zz]
ÎÄÕÂ×÷Õߣºcook702
ºÜ¶àѧϰ»ã±àµÄÅóÓÑÏë±Ø¶ÔCÒ²±È½ÏÁ˽⣬ÒòΪÔÚµ±Ç°´óѧµÄ¿Î³ÌÌåϵÀËüºÜÓпÉÄܾÍÊÇÄã½Ó´¥µ½µÄµÚÒ»Ãűà³ÌÓïÑÔ¡£ÓÉÓÚ¶Ô¼ÆËã»úµÄÀí½â²»¹»£¬Ñ§Ï°Ê±±Ø¶¨»áÓöµ½¸÷ÖÖÎÊÌâ¡£ÓÐЩÎÊÌâÊÇÄãͨ¹ý˼¿¼¾Í¿ÉÒÔ½â¾öµÄ£¬¶ø¸ü¶àµÄÎÊÌâÔòÊÇÄãÎÞ´Ó˼¿¼£¬¾ÍºÃÏñËüÌìÉú¾ÍÊÇÕâÑù£¬ÄãÖ»Òª¼ ......