題意:找相同字符竄首字母的地址
讀題。。。。 A word matches a straight, uninterrupted line of letters in the grid. The outputs of two consecutive cases will be separated by a blank line.這兩句haunted都沒讀出來。。。。一個說字符竄必須直線,一個說輸出在兩組數據內,第一個沒讀導致我用搜索TLE,第二個WA
#include<stdio.h> #include < string .h> char str[ 100 ][ 100 ],rem[ 100 ]; int t1[]={- 1 ,- 1 ,- 1 , 0 , 0 , 1 , 1 , 1 }; int t2[]={- 1 , 0 , 1 ,- 1 , 1 ,- 1 , 0 , 1 }; int len,m,n; void Rever( int row, int col, int ans) { if (str[row][col]>= ' A ' && str[row][col]<= ' Z ' ) str[row][col]+= 32 ; if (rem[ans]>= ' A ' && rem[ans]<= ' Z ' ) rem[ans]+= 32 ; } int Action( int row, int col) { int ans= 0 ,i; int x=row,y= col; Rever(row,col,ans); if (str[row][col]!=rem[ans]) return 0 ; for (i= 0 ;i< 8 ;i++ ) { ans = 0 ; while ( 1 ) { Rever(row,col,ans); if (row< 0 || col< 0 || row>=m || col>=n || str[row][col]!=rem[ans]) break ; { if (ans==len- 1 ) return 1 ; ans ++ ; row +=t1[i];col+= t2[i]; } } row =x;col= y; } return 0 ; } int main() { int i,j; int T,x,k; int flag; scanf( " %d " ,& T); while (T-- ) { scanf( " %d%d " ,&m,& n); for (i= 0 ;i<m;i++ ) { scanf( " %s " ,str[i]); } scanf( " %d " ,& x); for (k= 0 ;k<x;k++ ) { scanf( " %s " ,rem); len = strlen(rem); for (i= 0 ;i<m;i++ ) { for (j= 0 ;j<n;j++ ) { flag = 0 ; flag = Action(i,j); if (flag) break ; } if (flag) break ; } printf( " %d %d\n " ,i+ 1 ,j+ 1 ); } if (T!= 0 ) printf( " \n " ); } return 0 ; }
?
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
