原创 最大子序列和問題的三種實現(c語言)

#include <stdio.h> //由create_data.py產生的隨機數 int a[] = {-66,-83,14,-95,-7,42,39,-72,-100,-31,-57,47,99,-84,-96,-45,-38,

原创 stringtoint c++

static int string_to_int(const string &s) { if (s.empty()) { printf("rd_string_to_int string is empty\

原创 Leetcode第三題--無重複字符的最長子串(c實現)

給定一個字符串,請你找出其中不含有重複字符的 最長子串 的長度。 示例 1: 輸入: "abcabcbb" 輸出: 3  解釋: 因爲無重複字符的最長子串是 "abc",所以其長度爲  int lengthOfLongestSubstr

原创 c++ join

static string string_join(const vector<string> &vs, const string &delim) { string s; vector<string>::const_iterator

原创 最大子序列和

#include <stdio.h> //由create_data.py產生的隨機數 int a[] = {-66,-83,14,-95,-7,42,39,-72,-100,-31,-57,47,99,-84,-96,-45,-38,

原创 Leetcode第五題--最長迴文子串

給定一個字符串 s,找到 s 中最長的迴文子串。你可以假設 s 的最大長度爲 1000。 示例 1: 輸入: "babad" 輸出: "bab" 注意: "aba" 也是一個有效答案。 char * longestPalindrome(

原创 Leetcode第六題--Z 字形變換

將一個給定字符串根據給定的行數,以從上往下、從左到右進行 Z 字形排列。 比如輸入字符串爲 "LEETCODEISHIRING" 行數爲 3 時,排列如下: L C I R E T O E S I I G E D

原创 選擇第k個最小值

#include <stdio.h> #define CutOff (3) //截至範圍 void swap(int *a, int *b) { int tmp = *a; *a = *b; *b = tmp; } void

原创 Leetcode第二題--兩數相加(c實現)

 給出兩個 非空 的鏈表用來表示兩個非負的整數。其中,它們各自的位數是按照 逆序 的方式存儲的,並且它們的每個節點只能存儲 一位 數字。 如果,我們將這兩個數相加起來,則會返回一個新的鏈表來表示它們的和。 您可以假設除了數字 0 之外,這

原创 關於scanf輸入需要注意回車的問題

先上代碼 #include <stdio.h> int main() { char buf_1[256]; char buf_2[256]; scanf("%s", buf_1); scanf("%s", buf_2); p

原创 python有趣的 全局和局部變量

def test(): print(apple) apple = 'apple' apple = 'global apple' test() 運行這個程序會報錯,因爲apple雖然在apple = 'global apple'語句

原创 關於多線程與信號使用鎖的問題

在多線程程序中使用信號處理程序的時候,一定要注意,信號處理函數中一定不能使用鎖,信號處理函數應該儘可能的簡單,最好只是對於一些標誌位的賦值,然後再其他線程中,對標誌位進行輪詢查看,在線程中處理更多的邏輯。先上程序 #include <s

原创 簡單大數乘法的C 實現

12*34 = 12 x 34 ----- 48 36 ----- 408 #include <iostream> #in

原创 條款07:爲多態基類聲明virtual析構函數

Declare destructors virtual in polymorphic base classes. 有許多種做法可以記錄時間,因此,設計一個TimeKeeper base class和一些derived classes作爲不

原创 分塊計算大數乘法

  1234*5678 = 12 | 34 x 56 | 78 =====> 34*78 + 12*78*100 + 34*56*100 + 12*56*10000 #include <iost