Comment detail

四字熟語パズルの作成 (Nested Flatten)
LINQ使ってみました。

かなり怪しい出来ですが、
Pen4 2.8Ghz 303秒 24223件となりました。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace yojijukugo
{
    class Program
    {
        static public List<string> array = new List<string>();
        static public string[] outputStr = new string[4];
        static public int count = 0;

        static void Main(string[] args)
        {
            DateTime prev = DateTime.Now;

            // 1.ファイル読み取り
            using (StreamReader sr = new StreamReader(Settings1.Default.fileName))
            {
                while (sr.Peek() >= 0)
                    array.Add(sr.ReadLine());
            }

            for (int i = 0; i < array.Count; ++i)
            {
                var n = from a in array
                        where a[0] == array[i][0]
                        select a;
                if( n.Count() == 1 )
                    continue;

                foreach (string s in n)
                {
                    outputStr[0] = s;
                    logic(n);
                }

                i += (n.Count()-1);
            }

            DateTime now = DateTime.Now;

            Console.WriteLine(count);
            Console.WriteLine((now-prev).TotalSeconds.ToString());
            Console.Read();
        }

        public static void logic( IEnumerable<string> a )
        {
            var n = from b in a
                    where outputStr[0][3] != b[3]
                    && b != outputStr[0]
                    select b;

            var x = from c in array
                    where outputStr[0][3] == c[0]
                    && c != outputStr[0]
                    select c;

            foreach (string yj in n )
            {
                outputStr[1] = yj;

                var z = from d in array
                        where outputStr[1][3] == d[0]
                        && d != outputStr[0]
                        && d != outputStr[1]
                        select d;

                var y = from e in x
                        join f in z
                        on e[3] equals f[3]
                        where e != f
                        select new KeyValuePair<string, string>(e, f);

                foreach (KeyValuePair<string, string> kvp in y)
                {
                    outputStr[2] = kvp.Key;
                    outputStr[3] = kvp.Value;

                    Console.WriteLine(outputStr[1]);
                    Console.WriteLine(outputStr[0][1] + "  " + outputStr[3][1]);
                    Console.WriteLine(outputStr[0][2] + "  " + outputStr[3][2]);
                    Console.WriteLine(outputStr[2]);
                    Console.WriteLine();

                    count++;
                }
            }
        }
    }
}

Index

Feed

Other

Link

Pathtraq

loading...