[Source] 資源分享

好用資源

February 25, 2021 · 1 min · CPP

[Web] 讓我幫你 Google

利用工具 這次使用 HTML + CSS + JavaScript 的組合。 HTML : 網頁所看到的所有元件 CSS : 負責美編 JS : 呈現打字動畫及跳轉搜尋畫面 程式發想 打完字按下 送出,鎖定 按鈕不讓使用者再次送出, 顯示打字 動畫 ,最後 跳轉 到搜尋結果 程式實作 利用 setIntervel 來製作間隔動畫 var interval = setInterval(async function() { ... },intervalTime); 逐一增加文字到原文字長度 if (index == questionText.length) { clearInterval(interval); } 使用 setTimeout 來製作 delay 效果 var delay = setTimeout(function() { ... },forwardTime); 最後用 get 參數跳轉到 Google 網頁 window.location.assign("https://www.google.com/search?q=" + questionText); ㄏ ㄏ 一個很廢的小程式 ....

February 10, 2021 · 1 min · CPP

[Algorithm] 二分搜尋法

二分搜尋法 Binary Search 搜尋是一種很經典的演算法, 其中有一種搜尋法是將 已排序 的數列, 藉由比大小將數列分成 一半 並 縮小 搜尋範圍。 稱之為 「二分搜尋法」、「二元搜尋法」! #include <iostream> #include <algorithm> using namespace std; void binarySearch(int *number, int wanted, int strat, int stop); int main() { int number[105]; int n; while (cin>>n) { for (int i=0;i<n;i++) cin>>number[i]; sort(number,number+n); int m, wanted; cin>>m; for (int i=0;i<m;i++) { cin>>wanted; binarySearch(number, wanted, 0, n-1); cout<<endl; } } } void binarySearch(int *number, int wanted, int start, int stop) { int next = (start + stop) / 2; if (start > stop) { cout<<"error"; return ; } cout<<next<<" "<<number[next]<<" "; if (wanted > number[next]) binarySearch(number, wanted, next+1, stop); else if (wanted == number[next]) return ; else binarySearch(number, wanted, start, next-1); }

January 8, 2021 · 1 min · CPP

[Python] 特徵值

我只解出一元二次、三次方程式 . . . 我好爛 import math as math def toFactor(matrix) : length = len(matrix) if length == 4 : a, b = matrix[0], matrix[1] c, d = matrix[2], matrix[3] A = 1 B = (a+d) * (-1) C = a*d - b*c return A,B,C if length == 9 : a, b, c = matrix[0], matrix[1], matrix[2] d, f, g = matrix[3], matrix[4], matrix[5] h, j, l = matrix[6], matrix[7], matrix[8] A = 1 B = - a - f - l C = - b*d + a*f - c*h - g*j + a*l + f*l D = c*f*h + b*g*h + c*d*j + a*g*j + b*d*l - a*f*l return A,B,C,D if length == 16 : a, b, c, d = matrix[0], matrix[1], matrix[2], matrix[3] f, g, h, j = matrix[4], matrix[5], matrix[6], matrix[7] l, m, o, p = matrix[8], matrix[9], matrix[10], matrix[11] q, r, s, t = matrix[12], matrix[13], matrix[14], matrix[15] A = 1 B = - a - g - o - t C = - b*f + a*g - c*l - h*m + a*o + g*o - d*q - j*r - p*s + a*t + g*t + o*t D = ( c*g*l - b*h*l - c*f*m + a*h*m + b*f*o - a*g*o + d*g*q - b*j*q + d*o*q - c*p*q - d*f*r + a*j*r + j*o*r - h*p*r - d*l*s - j*m*s + a*p*s + g*p*s + b*f*t - a*g*t + c*l*t + h*m*t - a*o*t - g*o*t) E = (d*h*m*q - c*j*m*q - d*g*o*q + b*j*o*q + c*g*p*q - b*h*p*q - d*h*l*r + c*j*l*r + d*f*o*r - a*j*o*r - c*f*p*r + a*h*p*r + d*g*l*s - b*j*l*s - d*f*m*s + a*j*m*s + b*f*p*s - a*g*p*s - c*g*l*t + b*h*l*t + c*f*m*t - a*h*m*t - b*f*o*t + a*g*o*t) return A,B,C,D,E def solveFunction(f) : length = len(f) if length == 3 : A, B, C = f[0],f[1],f[2] x1 = ( -B + (B*B - 4*A*C)**(1/2)) / (2*A) x2 = ( -B - (B*B - 4*A*C)**(1/2)) / (2*A) return x1,x2 if length == 4 : A, B, C, D = f[0], f[1], f[2], f[3] p = ( -(B*B) / (3*A*A) ) + (C/A) q = ( (2*B*B*B) / (27*A*A*A) ) - ((B*C) / (3*A*A)) + (D/A) w = complex(-1,3**(1/2)) / 2 U = (-q / 2) + ( ( ( q / 2 )**2 + ( p / 3 )**3 )**(1/2) ) V = (-q / 2) - ( ( ( q / 2 )**2 + ( p / 3 )**3 )**(1/2) ) if U > 0 : U = math....

January 4, 2021 · 4 min · CPP

[Web] 新年快樂

為了應景一下,自己扣出新年倒數的網頁啦! 利用工具 這次使用 HTML + CSS + JavaScript 的組合。 HTML : 控制字及煙火的表現 CSS : 負責美編(字的效果、煙火的顏色) JS : 主要是倒數及內嵌 HTML 程式發想 倒數計時:到了 2021 01/01 00:00:00 就顯示 新年快樂 ,並且 放出煙火 程式實作 設定倒數終止時間 var countDownDate = new Date("Jan 1, 2021 00:00:00").getTime(); 每一秒重新取得新內容 (單位:毫秒) var x = setInterval(function() { // 函式內容 }, 1000); 取得現在的時間 (使用者系統時間) var now = new Date().getTime(); 更新並顯示倒數時間 使用 innerHTML 屬性,將文字內嵌到指定 id 的容器 document.getElementById("time").innerHTML = "倒數 " + hours + " 小時 " + minutes + " 分鐘 " + seconds + " 秒 "; 時間到了,就停止計時 clearInterval(x); document....

January 2, 2021 · 1 min · CPP