維基百科:沙盒

C♯-2這個用戶能一般地使用C♯

 


temp

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace asdgen1 {
    public class Form1 {
        public char[] kl="012345678".ToCharArray(),km="123456789123456789".ToCharArray();
        public Random R=new Random();
        public Form1() { }
        public string qgen() {
            StringBuilder s=new StringBuilder(); s.Length=81;
            List<char> q=new List<char>(kl),w=new List<char>(kl),e=new List<char>(),r=new List<char>(),kk=new List<char>(km);
            for(int i=0;i<9;i++) {
                Random m=new Random(R.Next());
                int j=m.Next(q.Count);
                e.Add(q[j]); q.RemoveAt(j);
                j=m.Next(w.Count);
                r.Add(w[j]); w.RemoveAt(j);
            } r.Add(r[0]);
            for(int i=0;i<9;i++) {
                Random m=new Random(R.Next());
                int j=m.Next(kk.Count);
                s[9*int.Parse(e[i].ToString())+int.Parse(r[i].ToString())]=kk[j];
                kk.RemoveAt(j);
                j=m.Next(kk.Count);
                s[9*int.Parse(e[i].ToString())+int.Parse(r[i+1].ToString())]=kk[j];
                kk.RemoveAt(j);
            }
            s.Replace('\0',' ');
            return s.ToString();
        }
        public string table3(params string[] x) {
            string y="<table border=0 cellspacing=0 cellpadding=0 style=border-style:solid>\r\n";
            for(int i=0;i<x.Length;i++) {
                y=y+(x[i]);
            } return y+"</table>";
        }
        public string table8(bool b,params string[] x) {
            return "<table width=100% border=0>\r\n<tr style=height:"+(b?"29":"37")+"px><td colspan=2></td></tr><tr valign=top style=height:276px><td width=4%></td><td width=46%>"+x[0]+
                "</td><td width=4%></td><td width=46%>"+x[1]+
                "</td></tr>\r\n<tr valign=top style=height:276px><td></td><td>"+x[2]+
                "</td><td></td><td>"+x[3]+
                "</td></tr>\r\n<tr valign=top style=height:276px><td></td><td>"+x[4]+
                "</td><td></td><td>"+x[5]+
                "</td></tr>\r\n<tr valign=top style=height:222px><td></td><td>"+x[6]+
                "</td><td></td><td>"+x[7]+"</td></tr>\r\n</table>";
        }
        public string totable(string x) {
            string[] a=new string[81];
            for(int i=0;i<81;i++) {
                string z="";
                if(i<x.Length&&"123456789".IndexOf(x[i])>=0) {
                    z=x[i].ToString();
                } a[i]=z;
            } string[] b=new string[27];
            for(int i=0;i<27;i++) {
                b[i]=tr3(true,a[3*i],a[3*i+1],a[3*i+2]);
            } string[] c=new string[9];
            for(int i=0;i<9;i++) {
                c[i]=table3(b[3*i],b[3*i+1],b[3*i+2]);
            } string[] d=new string[3];
            for(int i=0;i<3;i++) {
                d[i]=tr3(false,c[3*i],c[3*i+1],c[3*i+2]);
            } return table3(d[0],d[1],d[2]);
        }
        public string tr3(bool b,params string[] x) {
            string y="<tr>";
            for(int i=0;i<x.Length;i++) {
                y=y+("<td style=border:none><div class=\"block60"+(b?" block20":"")+"\">"+x[i]+"</div></td>");
            } return y+"</tr>\r\n";
        }
        public void Form1_Click(object sender,EventArgs e) {
            //if(s.ShowDialog()!=DialogResult.OK) { return; }
            StreamWriter f=new StreamWriter(/*s.FileName*/"out.htm");
            f.WriteLine("<html><head><style>body{font-family:MingLiu}");
            f.WriteLine(".block20{font-size:16px;width:20px;height:20px;line-height:20px}");
            f.WriteLine(".block60{text-align:center;word-break:break-all;border:solid 1px #000}</style></head><body>");
            for(int i=0;i<2;i++) {
                f.WriteLine(table8(i==0,totable(qgen()),totable(qgen()),totable(qgen()),totable(qgen()),totable(qgen()),totable(qgen()),totable(qgen()),totable(qgen())));
                if(i<1) { f.WriteLine("<p style=page-break-before:always></p>"); }
            } f.WriteLine("</body></html>"); f.Close();
        }
    }
    class pr {
        static void Main(string[] args) {
            new Form1().Form1_Click(null,null);
        }
    }
}