user-0 提问: ACM基础题Peg（跳棋）求助

回复:
user: user-1
content: 正确的写法是把两段分开： for(i = 0; i < 5; i++){     for(j = 0; j < 7; j++){         if(board[i][j] == 'o' && board[i+1][j] == 'o' && board[i+2][j] == '.')         counter ++;         else if(board[i][j] == '.' && board[i+1][j] == 'o' && board[i+2][j] == 'o')         counter ++;         }     }  for(i = 0; i < 7; i++){     for(j = 0; j < 5; j++){         if(board[i][j] == 'o' && board[i][j+1] == 'o' && board[i][j+2] == '.')         counter ++;         else if(board[i][j] == '.' && board[i][j+1] == 'o' && board[i][j+2] == 'o')         counter ++;         }     }

user: user-1
content: 你的算法只遍历了2个5*7的区域，遗漏了7*7右下角2*2的区域 例如：board[5][4]='.' board[5][5]='o' board[5][6]='o'

user: user-2
content: 代码贴错了，应该是这个：//1 2 3 //4 5 6 求一笔划过所有9个键的所有方法 //7 8 9 #include <stdio.h> int g[10][9]={     {0,0,0,0,0,0,0,0,0},     {2,4,5,0,0,0,0,0,0},//1     {1,3,4,5,6,0,0,0,0},//2     {2,5,6,0,0,0,0,0,0},//3     {1,2,5,7,8,0,0,0,0},//4     {1,2,3,4,6,7,8,9,0},//5     {2,3,5,8,9,0,0,0,0},//6     {4,5,8,0,0,0,0,0,0},//7     {4,5,6,7,9,0,0,0,0},//8     {5,6,8,0,0,0,0,0,0},//9 }; int k,i,n; int h[10];//记录是否划过h[1..9],history int p[10];//记录划的顺序p[1..9],path void go(int f,int L) {     int j;      if (L==9) {         p[L]=f;         n++;         printf("%08d:",n);         for (i=1;i<=9;i++) printf(" %d",p[i]);         printf("\n");     } else {         p[L]=f;         h[f]=1;         j=0;         while (1) {             if (g[f][j]==0) break;             if (h[g[f][j]]==0) {                 go(g[f][j],L+1);                 h[g[f][j]]=0;             }             j++;         }     } } int main() {     n=0;     for (k=1;k<=9;k++) {         for (i=1;i<=9;i++) h[i]=0;         go(k,1);     }     return 0; } //00000001: 1 2 3 5 4 7 8 6 9 //00000002: 1 2 3 5 4 7 8 9 6 //00000003: 1 2 3 5 6 9 8 4 7 //00000004: 1 2 3 5 6 9 8 7 4 //00000005: 1 2 3 5 7 4 8 6 9 //00000006: 1 2 3 5 7 4 8 9 6 //00000007: 1 2 3 5 9 6 8 4 7 //00000008: 1 2 3 5 9 6 8 7 4 //00000009: 1 2 3 6 5 4 7 8 9 //00000010: 1 2 3 6 5 7 4 8 9 //00000011: 1 2 3 6 5 9 8 4 7 //00000012: 1 2 3 6 5 9 8 7 4 //00000013: 1 2 3 6 8 4 7 5 9 //00000014: 1 2 3 6 8 7 4 5 9 //00000015: 1 2 3 6 8 9 5 4 7 //00000016: 1 2 3 6 8 9 5 7 4 //00000017: 1 2 3 6 9 5 4 7 8 //00000018: 1 2 3 6 9 5 4 8 7 //00000019: 1 2 3 6 9 5 7 4 8 //00000020: 1 2 3 6 9 5 7 8 4 //00000021: 1 2 3 6 9 5 8 4 7 //00000022: 1 2 3 6 9 5 8 7 4 //00000023: 1 2 3 6 9 8 4 5 7 //00000024: 1 2 3 6 9 8 4 7 5 //00000025: 1 2 3 6 9 8 5 4 7 //00000026: 1 2 3 6 9 8 5 7 4 //00000027: 1 2 3 6 9 8 7 4 5 //00000028: 1 2 3 6 9 8 7 5 4 //00000029: 1 2 4 5 3 6 9 8 7 //00000030: 1 2 4 5 7 8 9 6 3 //00000031: 1 2 4 7 5 3 6 8 9 //00000032: 1 2 4 7 5 3 6 9 8 //00000033: 1 2 4 7 5 8 9 6 3 //00000034: 1 2 4 7 5 9 8 6 3 //00000035: 1 2 4 7 8 5 3 6 9 //00000036: 1 2 4 7 8 5 9 6 3 //00000037: 1 2 4 7 8 6 3 5 9 //00000038: 1 2 4 7 8 6 9 5 3 //00000039: 1 2 4 7 8 9 5 3 6 //00000040: 1 2 4 7 8 9 5 6 3 //00000041: 1 2 4 7 8 9 6 3 5 //00000042: 1 2 4 7 8 9 6 5 3 //00000043: 1 2 4 8 7 5 3 6 9 //00000044: 1 2 4 8 7 5 9 6 3 //00000045: 1 2 4 8 9 6 3 5 7 //00000046: 1 2 5 3 6 9 8 4 7 //00000047: 1 2 5 3 6 9 8 7 4 //00000048: 1 2 5 4 7 8 9 6 3 //00000049: 1 2 5 7 4 8 9 6 3 //00000050: 1 2 6 3 5 4 7 8 9 //00000051: 1 2 6 3 5 7 4 8 9 //00000052: 1 2 6 3 5 9 8 4 7 //00000053: 1 2 6 3 5 9 8 7 4 //00000054: 1 2 6 9 8 4 7 5 3 //00000055: 1 2 6 9 8 7 4 5 3 //00000056: 1 4 2 3 5 6 9 8 7 //... ... //00000776: 9 8 7 4 5 6 3 2 1 //00000777: 9 8 7 5 1 4 2 3 6 //00000778: 9 8 7 5 1 4 2 6 3 //00000779: 9 8 7 5 3 6 2 1 4 //00000780: 9 8 7 5 3 6 2 4 1 //00000781: 9 8 7 5 4 1 2 3 6 //00000782: 9 8 7 5 4 1 2 6 3 //00000783: 9 8 7 5 6 3 2 1 4 //00000784: 9 8 7 5 6 3 2 4 1

user: user-2
content: 思路应该有可参考的地方吧。我觉得。

user: user-0
content: @赵4老师  老师，回复错地方了吧

user: user-2
content: 仅供参考：//手机的键盘是这样的： // 1      2 abc  3 def // 4 ghi  5 jkl  6 mno // 7 pqrs 8 tuv  9 wxyz // *      0      # //要按出英文字母就必须要按数字键多下。例如要按出x就得按9两下，第一下会出w，而第二下会把w变成x。0键按一下会出一个空格。 //读取若干句只包含英文小写字母和空格的句子，求出要在手机上打出这个句子至少需要按多少下键盘。 #include <stdio.h> #include <string.h> char n[127]; char s[]="i have a dream"; char c; int L,i,k; int main() {     n[' ']=1;     n['a']=1;     n['b']=2;     n['c']=3;     n['d']=1;     n['e']=2;     n['f']=3;     n['g']=1;     n['h']=2;     n['i']=3;     n['j']=1;     n['k']=2;     n['l']=3;     n['m']=1;     n['n']=2;     n['o']=3;     n['p']=1;     n['q']=2;     n['r']=3;     n['s']=4;     n['t']=1;     n['u']=2;     n['v']=3;     n['w']=1;     n['x']=2;     n['y']=3;     n['z']=4;     k=0;     L=strlen(s);     for (i=0;i<L;i++) {         printf("%2d %c  %d\n",i,s[i],n[s[i]]);         k+=n[s[i]];     }     printf("Total %d\n",k);     return 0; } // 0 i  3 // 1    1 // 2 h  2 // 3 a  1 // 4 v  3 // 5 e  2 // 6    1 // 7 a  1 // 8    1 // 9 d  1 //10 r  3