标签:sync for cin sudo += null false lse ids
1 static int wing=[]() 2 { 3 std::ios::sync_with_stdio(false); 4 cin.tie(NULL); 5 return 0; 6 }(); 7 8 class Solution 9 { 10 public: 11 unordered_map<char,int> cimap={{‘1‘,0},{‘2‘,0},{‘3‘,0},{‘4‘,0},{‘5‘,0},{‘6‘,0},{‘7‘,0},{‘8‘,0},{‘9‘,0}}; 12 unordered_map<char,int> cur; 13 bool isValidSudoku(vector<vector<char>>& board) 14 { 15 for(int i=0;i<9;i++) 16 { 17 cur=cimap; 18 for(int j=0;j<9;j++) 19 { 20 char curchar=board[i][j]; 21 if(curchar==‘.‘) 22 continue; 23 else 24 { 25 cur[curchar]++; 26 if(cur[curchar]>1) 27 return false; 28 } 29 } 30 } 31 for(int i=0;i<9;i++) 32 { 33 cur=cimap; 34 for(int j=0;j<9;j++) 35 { 36 char curchar=board[j][i]; 37 if(curchar==‘.‘) 38 continue; 39 else 40 { 41 cur[curchar]++; 42 if(cur[curchar]>1) 43 return false; 44 } 45 } 46 } 47 for(int i=0;i<9;i+=3) 48 { 49 for(int j=0;j<9;j+=3) 50 { 51 if(judgesub(board,i,j)) 52 continue; 53 else 54 return false; 55 } 56 } 57 return true; 58 } 59 60 bool judgesub(vector<vector<char>>& board,int i,int j) 61 { 62 int szx=i+3,szy=j+3; 63 cur=cimap; 64 for(int x=i;x<szx;x++) 65 { 66 for(int y=j;y<szy;y++) 67 { 68 char c=board[x][y]; 69 if(c==‘.‘) 70 continue; 71 else 72 { 73 cur[c]++; 74 if(cur[c]>1) 75 return false; 76 } 77 } 78 } 79 return true; 80 } 81 };
顺序验证即可,问题不大
标签:sync for cin sudo += null false lse ids
原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9280732.html