1. 程式人生 > >落谷P1101 單詞方陣 //未完成

落谷P1101 單詞方陣 //未完成

space code cout 完成 ace else lin for const

 1 #include<iostream>/*cout<<endl;
 2 for(int i=1;i<=n;i++)
 3 for(int j=0;j<n;j++){
 4 
 5 cout<<a[i][j];
 6 if(j==n-1)cout<<endl;
 7 }*/
 8 #include<cstring>
 9 #include<cstdio>
10 using namespace std;
11 const int wd=101;
12 bool how[wd][wd];
13 char a[wd][wd];
14 int n=0; 15 int drx[8]={0,0,1,-1,1,-1,-1,1}, 16 dry[8]={1,-1,0,0,1,1,-1,-1};//方向 17 char word[7]={y,i,z,h,o,n,g}; //搜索關鍵字 18 inline void sar(int x,int y,int d,int c){//坐標x,y 方向 字符位置 19 int xx=0,yy=0; 20 if(d==-1){ 21 for(int i=0;i<8;i++){ 22 xx=x+drx[i];
23 yy=y+drx[i]; 24 if(a[xx][yy]==word[c])sar(xx,yy,i,c+1);//方向不變 25 } 26 return; 27 } 28 if(c==7){ 29 x=xx;y=yy; 30 for(int i=1;i<=7;i++){ 31 how[x][y]=1; 32 xx-=drx[d]; 33 yy-=dry[d]; 34 } 35 return; 36 } 37 xx=x+drx[d];
38 yy=y+drx[d]; 39 if(a[xx][yy]==word[c])sar(xx,yy,d,c+1); 40 } 41 42 int main(){ 43 scanf("%d",&n); 44 for(int i=1;i<=n;i++)scanf("%s",a[i]+1);//輸入測試完成 45 for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){ 46 if(a[i][j]==y)sar(i,j,-1,1); 47 } 48 for(int i=1;i<=n;i++) 49 {cout<<endl; 50 for(int j=1;j<=n;j++){ 51 cout<<how[i][j]; 52 if(how[i][j]==1)cout<<a[i][j]; 53 else cout<<"*"; 54 }} 55 return 0; 56 }

落谷P1101 單詞方陣 //未完成