首页 > 其他分享 >数独辅助工具

数独辅助工具

时间:2022-10-22 23:36:56浏览次数:52  
标签:replace className item let 辅助工具 tds td 数独

<html dir="ltr" lang="zh" class="focus-outline-visible" style="background-color: rgb(255, 255, 255);background-image: unset;t: rgba(0, 0, 0, 1);"><head>
    <meta charset="utf-8">
    <title>数独</title>
    <!-- <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/> -->
    <style>
        table{
            background:#FF0000;
            margin:20px auto;
        }
        .footer{
            margin:20px auto;
            text-align:center;
        }
        td{
            width:50px;
            height:50px;
            font-size:30px;
            color:BLACK;
            font-weight:bolder;
        }
        td.fixed{
            color:BROWN;
        }
        td.hover{
            background:#CCFFEE!important;
        }
        td.tip{
            
            background:#7895f7!important;
        }
        td.active{
            opacity: 1;
            font-size:40px;
            background:BROWN!important;
            color:#FFFFFF!important;
        }
        input{
            line-height:30px;
        }
        .btn{
            background: #F3FD9D;
            border: none;
            line-height: 34px;
            border-radius: 4px;
            width:100px;
            
        }
    </style></head>
  <body>
    <table contenteditable="true" border="1" style="
    width: 500px;
    height: 500px;
    text-align: center;
    line-height: 50px;
">

        <tbody><tr>
            <td></td>
            <td></td>
            <td class="fixed" contenteditable="false">5</td>
            <td></td>
            <td></td>
            <td class="fixed" contenteditable="false">7</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td class="fixed" contenteditable="false">9</td>
            <td class="fixed" contenteditable="false">3</td>
            <td></td>
            <td></td>
            <td class="fixed" contenteditable="false">7</td>
        </tr>
        <tr>
            <td class="fixed" contenteditable="false">6</td>
            <td></td>
            <td class="fixed" contenteditable="false">1</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td class="fixed" contenteditable="false">9</td>
        </tr>
        <tr>
            <td></td>
            <td class="fixed" contenteditable="false">1</td>
            <td class="fixed" contenteditable="false">2</td>
            <td></td>
            <td></td>
            <td class="fixed" contenteditable="false">4</td>
            <td></td>
            <td class="fixed" contenteditable="false">9</td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td class="fixed" contenteditable="false">5</td>
            <td></td>
            <td class="fixed" contenteditable="false">9</td>
            <td></td>
            <td class="fixed" contenteditable="false">1</td>
            <td></td>
            <td class="fixed" contenteditable="false">8</td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td class="fixed" contenteditable="false">9</td>
            <td></td>
            <td class="fixed" contenteditable="false">6</td>
            <td></td>
            <td></td>
            <td class="fixed" contenteditable="false">2</td>
            <td class="fixed" contenteditable="false">5</td>
            <td></td>
        </tr>
        <tr>
            <td class="fixed" contenteditable="false">5</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td class="fixed" contenteditable="false">1</td>
            <td></td>
            <td class="fixed" contenteditable="false">2</td>
        </tr>
        <tr>
            <td class="fixed" contenteditable="false">1</td>
            <td></td>
            <td></td>
            <td class="fixed" contenteditable="false">4</td>
            <td class="fixed" contenteditable="false">5</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="fixed" contenteditable="false">7</td>
            <td></td>
            <td></td>
            <td class="fixed" contenteditable="false">9</td>
            <td></td>
            <td></td>
        </tr>
    </tbody></table>
    <div class="footer">
        <input type="text" id="number" />
        
        <button class="btn" onclick="tip()">提示</button>
    </div>
    
    <script>
    let tds = document.querySelectorAll("td");
    tds.forEach((td, idx) => {
        let row = Math.floor(idx / 9);
        let col = idx % 9;
        let bRow = Math.floor(idx / 9 / 3);
        let bCol = Math.floor(idx % 9 / 3);
        let group = bRow * 3 + bCol;
        let colors = ["#FFFFFF", "#EEEECC","#FFFFFF", "#EEEECC","#FFFFFF", "#EEEECC","#FFFFFF","#EEEECC", "#FFFFFF"];
        td.style.background = colors[group];
        td.x = col;
        td.y = row;
        td.g = group;
        
        td.onclick = function(){
            
            tds.forEach(item => {
                let className = item.className || "";
                className = className.replace(/\s?tip/g, "").replace(/\s?active/g, "").replace(/\s?hover/g, "");
                if(item.x == this.x || item.y == this.y){
                    className = className + " hover";
                }
                item.className = className;
            })
            if(this.innerText){
                document.getElementById("number").value = this.innerText;
            }
            
        }

        /*td.onmouseleave = function(){
            
            tds.forEach(item => {
                let className = item.className || "";
                className = className.replace(/\s?tip/g, "").replace(/\s?active/g, "").replace(/\s?hover/g, "");
                
                item.className = className;
            })
        }*/
        
    })
    
    function tip(){
        let number = document.getElementById("number").value;
        if(!number){
            return false;
        }
        let xs = [];
        let ys = [];
        let gs = [];
        tds.forEach((td, idx) => {
            let className = td.className || "";
            className = className.replace(/\s?tip/g, "").replace(/\s?active/g, "").replace(/\s?hover/g, "");
            td.className = className;
            
        });
        tds.forEach((td, idx) => {
            let val = td.innerText.trim();
            if(val == number){
                xs.push(td.x);
                ys.push(td.y);
                gs.push(td.g);
                let className = td.className || "";
                className = className + " active";
                td.className = className;
            }
        });
        
        
        tds.forEach(item => {
            let className = item.className || "";
            if(!xs.includes(item.x) && !ys.includes(item.y) && !gs.includes(item.g) && !item.innerText){
                className = className + " tip";
                item.className = className;
            }
            
            
        })
    }
    
    
    </script>
</body></html>

 

标签:replace,className,item,let,辅助工具,tds,td,数独
From: https://www.cnblogs.com/rubekid/p/16817590.html

相关文章

  • 三种常用的辅助工具类
    三种常用的辅助工具类CountDownLatch是一个执行减法操作的辅助计数器//计数器publicclassCountDownLatchTest{publicstaticvoidmain(String[]args)thr......
  • P1784 数独
    数独题目描述数独是根据\(9\times9\)盘面上的已知数字,推理出所有剩余空格的数字,并满足每一行、每一列、每一个粗线宫内的数字均含\(1-9\),不重复。每一道合格的数......
  • 理解错题了 36. 有效的数独
     理解错题了,就是让你在矩阵中循环判断而已,我还想到了康托付展开请你判断一个 9x9的数独是否有效。只需要根据以下规则,验证已经填入的数字是否有效即可。数字 1-9......
  • 算法与数据结构--有效数独
    classSolution{public:boolisValidSudoku(vector<vector<char>>&board){introws[9][9];//建造一个二维数组,记录行intcolumns[9][9];//建......
  • 蓝湖辅助工具使用介绍
    工具下载链接地址(免费):https://download.csdn.net/download/qq_35166501/86565258网页界面  界面展示下载和使用步骤1.打开链接https://download.csdn.net/d......
  • 数独
    https://www.acwing.com/problem/content/168/#include<algorithm>#include<iostream>usingnamespacestd;constintN=9;//0-511//ones[i]表示i这个数......
  • 介绍一个博客图片上传辅助工具
    前言熟悉我的朋友可能知道,我从18年开始尝试的写一些文字记录一些东西;最开始我是在CSDN上进行创作,后面由于实在忍受不了CSDN上面各种商业化产品转战到博客园。由于之前一......
  • [AcWing 166] 数独
    DFS+剪枝+位运算优化点击查看代码#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;constintN=9,M=1<<N;intones[M];//on......
  • 36.有效的数独
      输入:board=[["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".","."......
  • HashMap-有效的数独
    问题描述:判断一个9x9的数独是否有效。只需要根据以下规则,验证已经填入的数字是否有效即可:数字1-9在每一行只能出现一次。数字1-9在每一列只能出现一次。数字......