4. 「大數據」之資料處理

不太理解這題在考什麼,完全沒邏輯。假設只需要做好範例的內容,我就偵測開頭做4個case就好了...

using System.Globalization;
using System.Runtime.InteropServices;

namespace Q4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            textBox1.Text = new StreamReader(openFileDialog1.OpenFile()).ReadToEnd();
            var k = "";
            var s = textBox1.Text;
            while (s.EndsWith('?')) s = s.Substring(0, s.Length - 1);
            char[] ch = s.ToCharArray();
            bool nextParenthess = false;
            int firstSlash = -1;
            for (int i = 0; i < ch.Length; i++)
            {
                char c = ch[i];
                char? next = i == ch.Length - 1 ? null : ch[i + 1];
                char? last = i == 0 ? null : ch[i - 1];
                if ((c == ':' || c == ' ') && c == next) continue;

                if (firstSlash == -1)
                {
                    if (c == ' ')
                    {
                        firstSlash = 0;
                    }
                    else if (c == '/') firstSlash = 1;
                }

                if ((firstSlash == 0 ? c == ' ' : c == '/') &&
                    next != null && !(next == '(' || next >= 'A' && next <= 'Z' || next >= '0' && next <= '9' || next >= 'a' && next <= 'z')
                    && next != '熱')
                {
                    k += "\r\n";
                    continue;
                }
                if (c == '(' && last >= '0' && last <= '9')
                {
                    k += "\r\n";
                    nextParenthess = true;
                    continue;
                }
                if (c == ')' && nextParenthess)
                {
                    nextParenthess = false;
                    k += "\r\n";
                    i++;
                    continue;
                }
                k += c;
            }
            textBox2.Text = k;
        }
    }
}

Last updated