通常當我們宣告資料型態的時候,其實是在跟系統要記憶體。
例如說 int a = 1;
int 真正的意思是,給我4位元組我要放整數,也就是4*8=32個位元的空間長度。
而int能表現多少的數字呢,因為有32位元,然後一個位元能表現0跟1兩種,所以一共就是232種數字,但因為有正負號,所以是-2147483648 ~ 2147483647。
所以記各資料型態的大小的時候,只記位元組(byte),能表示多少種數字,就是2的該位元組*8。
以下都有unsigned的型態,unsigned的長度不變,表現數字皆為正數沒有負號。
int 4 bytes = 32 bits = 232
char 1 bytes = 8 bits = 28
short 2 bytes = 16 bits = 216
long 4 bytes = 32 bits = 232
long long 8 bytes = 64 bits = 264
浮點數皆有號:
float 4 bytes = 32 bits = 232
double 8 bytes = 64 bits = 264
參考自這裡
標籤
二元樹
(1)
字串常數池
(1)
投資
(3)
每月損益
(37)
例外處理
(1)
泛型
(2)
股票
(15)
指標
(5)
英文
(8)
基本資料型別
(1)
期貨
(1)
程式交易
(10)
量化投資
(5)
亂亂寫
(3)
概念
(3)
資料結構
(3)
演算法
(3)
數學
(3)
轉型
(1)
AMA
(1)
ArrayList
(1)
assert
(1)
BeautifulSoup
(1)
C/C++
(8)
casting
(1)
ClassCastException
(1)
classpath
(1)
Collection
(4)
Comparable
(1)
comparTo()
(1)
constructor
(1)
database
(3)
Debian
(1)
Dropbox
(2)
EA
(2)
enum
(1)
equals()
(2)
exception
(3)
extends
(1)
ffmpeg
(1)
final
(1)
Git
(1)
HashMap
(1)
HashSet
(1)
hasNext()
(1)
HTS
(3)
instanceof
(1)
IS-A
(1)
Iterator
(1)
JAVA
(43)
length
(1)
Linux
(31)
List
(1)
Mac
(6)
Map
(1)
ML
(2)
MT4
(6)
MySQL
(2)
next()
(1)
NullPointerException
(1)
Number
(1)
Numpy
(2)
OpenCart
(1)
OpenCV
(3)
OSX
(1)
overloading
(1)
overriding
(3)
pandas
(2)
PHP
(8)
PriorityQueue
(1)
Python
(11)
Queue
(1)
random()
(1)
reverse()
(1)
Samba
(1)
SCJP
(21)
sqrt()
(1)
synchronized
(1)
talib
(1)
ufw
(1)
uTorrent
(1)
var-args
(2)
VHF
(1)
vim
(2)
Yhoo知識+
(4)
2011年11月26日 星期六
111113_利用C為點陣圖做自動對比
#include <stdio.h>
#include <stdlib.h>
#define write_path "output.bmp" //輸出圖檔的檔名
void GCS(const char*, const char*); //global contrast stretching(全域對比調整)
int main(void)
{
char select[10];
char exit[5] = "exit";
while(1){
printf("請輸入圖片檔名(包含副檔名,例: input.bmp),輸入exit為結束: ");
scanf("%s", &select);
if(strcmp(select, exit) == 0){
printf("程式結束!\n") ;
system("PAUSE");
return 0;
}
GCS(select, write_path);
}
return 0;
}
void GCS(const char *input, const char *output){
unsigned char bmp_head[54]={0}; //存放bmp的標頭檔
unsigned char *data_buf; //BMP的資料
unsigned int i,j;
unsigned int width=0, high=0; //BMP圖檔的寬與高
unsigned int bmp_w; //BMP資料陣列每一列長度
int max=0, min=255;
char exit[] = "exit";
FILE *fp1; //輸入檔
FILE *fp2; //輸出檔
fp1 = fopen(input, "rb" ); //讀取二進位圖檔並寫入
fp2 = fopen(output, "w+b" ); //新建二進位檔並讀取寫入
if(fp1 == NULL){
printf("檔案找不到!\n");
return;
}
fread(bmp_head,54,1,fp1); //讀取來源標頭檔
fwrite(bmp_head,54,1,fp2); //寫入標頭檔至fp2
//從標頭檔讀出BMP圖檔寬度及高度 (單位:像素)
width = *(bmp_head+18) + 256*(*(bmp_head+19)) + 256*256*(*(bmp_head+20)) + 256*256*256*(*(bmp_head+21));
high = *(bmp_head+22) + 256*(*(bmp_head+23)) + 256*256*(*(bmp_head+24)) + 256*256*256*(*(bmp_head+25));
printf("%d\n", *(bmp_head+28));
printf("%d %d %d %d\n", *(bmp_head+18),*(bmp_head+19),*(bmp_head+20),*(bmp_head+21));
printf("%d %d %d %d\n", *(bmp_head+22),*(bmp_head+23),*(bmp_head+24),*(bmp_head+25));
printf("%d %d\n", width,high);
//BMP資料陣列每一列長度為:
//像素寬度X顏色深度,即width*3(以24bits的BMP為例)
bmp_w=width*3;
//每一列長度須為4的倍數,所以要加上4-(width*3)%4
if(bmp_w % 4) bmp_w += 4-(bmp_w % 4);
//跟系統要BMP資料陣列一列長度的記憶體
data_buf = (unsigned char *) malloc(sizeof(unsigned char)*bmp_w);
for(i=0; i<high; i++){
fread(data_buf, bmp_w, 1, fp1); //每次從fp1讀取一列BMP陣列至data_buf
for(j=0; j<width; j++){
if(data_buf[j] > max) max = data_buf[j];
if(data_buf[j] < min) min = data_buf[j];
}
}
fp1 = fopen(input, "r+b");
fread(bmp_head,54,1,fp1);
for(i=0; i<high; i++){
fread(data_buf, bmp_w, 1, fp1); //每次從fp1讀取一列BMP陣列至data_buf
for(j=0; j<width*3; j+=3){
data_buf[j] = 255*(data_buf[j+2]-min)/(max-min);
data_buf[j+1] = 255*(data_buf[j+1]-min)/(max-min);
data_buf[j+2] = 255*(data_buf[j]-min)/(max-min);
}
fwrite(data_buf,bmp_w,1,fp2); //將data_buf存入fp2檔
}
fclose(fp1);
fclose(fp2);
printf("Local contrast stretching處理完成!\n請開啟檔案 "write_path"\n\n");
}
#include <stdlib.h>
#define write_path "output.bmp" //輸出圖檔的檔名
void GCS(const char*, const char*); //global contrast stretching(全域對比調整)
int main(void)
{
char select[10];
char exit[5] = "exit";
while(1){
printf("請輸入圖片檔名(包含副檔名,例: input.bmp),輸入exit為結束: ");
scanf("%s", &select);
if(strcmp(select, exit) == 0){
printf("程式結束!\n") ;
system("PAUSE");
return 0;
}
GCS(select, write_path);
}
return 0;
}
void GCS(const char *input, const char *output){
unsigned char bmp_head[54]={0}; //存放bmp的標頭檔
unsigned char *data_buf; //BMP的資料
unsigned int i,j;
unsigned int width=0, high=0; //BMP圖檔的寬與高
unsigned int bmp_w; //BMP資料陣列每一列長度
int max=0, min=255;
char exit[] = "exit";
FILE *fp1; //輸入檔
FILE *fp2; //輸出檔
fp1 = fopen(input, "rb" ); //讀取二進位圖檔並寫入
fp2 = fopen(output, "w+b" ); //新建二進位檔並讀取寫入
if(fp1 == NULL){
printf("檔案找不到!\n");
return;
}
fread(bmp_head,54,1,fp1); //讀取來源標頭檔
fwrite(bmp_head,54,1,fp2); //寫入標頭檔至fp2
//從標頭檔讀出BMP圖檔寬度及高度 (單位:像素)
width = *(bmp_head+18) + 256*(*(bmp_head+19)) + 256*256*(*(bmp_head+20)) + 256*256*256*(*(bmp_head+21));
high = *(bmp_head+22) + 256*(*(bmp_head+23)) + 256*256*(*(bmp_head+24)) + 256*256*256*(*(bmp_head+25));
printf("%d\n", *(bmp_head+28));
printf("%d %d %d %d\n", *(bmp_head+18),*(bmp_head+19),*(bmp_head+20),*(bmp_head+21));
printf("%d %d %d %d\n", *(bmp_head+22),*(bmp_head+23),*(bmp_head+24),*(bmp_head+25));
printf("%d %d\n", width,high);
//BMP資料陣列每一列長度為:
//像素寬度X顏色深度,即width*3(以24bits的BMP為例)
bmp_w=width*3;
//每一列長度須為4的倍數,所以要加上4-(width*3)%4
if(bmp_w % 4) bmp_w += 4-(bmp_w % 4);
//跟系統要BMP資料陣列一列長度的記憶體
data_buf = (unsigned char *) malloc(sizeof(unsigned char)*bmp_w);
for(i=0; i<high; i++){
fread(data_buf, bmp_w, 1, fp1); //每次從fp1讀取一列BMP陣列至data_buf
for(j=0; j<width; j++){
if(data_buf[j] > max) max = data_buf[j];
if(data_buf[j] < min) min = data_buf[j];
}
}
fp1 = fopen(input, "r+b");
fread(bmp_head,54,1,fp1);
for(i=0; i<high; i++){
fread(data_buf, bmp_w, 1, fp1); //每次從fp1讀取一列BMP陣列至data_buf
for(j=0; j<width*3; j+=3){
data_buf[j] = 255*(data_buf[j+2]-min)/(max-min);
data_buf[j+1] = 255*(data_buf[j+1]-min)/(max-min);
data_buf[j+2] = 255*(data_buf[j]-min)/(max-min);
}
fwrite(data_buf,bmp_w,1,fp2); //將data_buf存入fp2檔
}
fclose(fp1);
fclose(fp2);
printf("Local contrast stretching處理完成!\n請開啟檔案 "write_path"\n\n");
}
111103_數學_韓信點兵
韓信點兵三人一數多一人,五人一數多三人,七人一數多五人,請問最少有多少兵?
先求3, 5, 7的最小公倍數為105 ,
再看題目發現都不足2人,
所以答案是105 - 2 = 103
百萬小學堂的國小題目
先求3, 5, 7的最小公倍數為105 ,
再看題目發現都不足2人,
所以答案是105 - 2 = 103
百萬小學堂的國小題目
111028_C_malloc()_動態記憶體配置
malloc()簡單的說就是跟系統要空間,若成功會回傳一個指標,指出該空間的記憶體位置;因回傳的是一個void *,必須指定它的型態,在前面加上如(int *)來指定;若不成功則回傳null。
//跟系統要一個整數大小的記憶體空間
int* a;
a = (int *)malloc(sizeof(int)); //告訴系統這空間是要存放整數
//跟系統要一個字元大小的記憶體空間
char* ch;
ch = (char *)malloc(sizeof(int)); //告訴系統這空間是要存放字元
//如果直接寫大小一定要寫對
int* a;
a = (int *)malloc(1); //如果是整數卻配1個byte,編譯器會把後面3個byte直接拿來存取,然後系統就當機給你看
//要一個長度為10的整數陣列
int* a;
a = (int*)malloc(sizeof(int) * 10);
參考資料:這裡,跟這裡
//跟系統要一個整數大小的記憶體空間
int* a;
a = (int *)malloc(sizeof(int)); //告訴系統這空間是要存放整數
//跟系統要一個字元大小的記憶體空間
char* ch;
ch = (char *)malloc(sizeof(int)); //告訴系統這空間是要存放字元
//如果直接寫大小一定要寫對
int* a;
a = (int *)malloc(1); //如果是整數卻配1個byte,編譯器會把後面3個byte直接拿來存取,然後系統就當機給你看
//要一個長度為10的整數陣列
int* a;
a = (int*)malloc(sizeof(int) * 10);
參考資料:這裡,跟這裡
2011年11月22日 星期二
2011年11月19日 星期六
111104_C++_ifstream建立輸入檔
ifstream是一個類別,要使用必須先建立一個ifstream物件。
ifstream類別有開啟檔案的方法:open,所以當你要開啟一個檔案時,必須這樣寫:
ifstream inputfile;
inutfile.open("input.txt");
也可以:
inutfile.open("input.txt", iso::in);
ios::in 開啟可供讀取資料的檔案
參考:
http://caterpillar.onlyfun.net/Gossip/CppGossip/UnFormatFileIO.html
ifstream類別有開啟檔案的方法:open,所以當你要開啟一個檔案時,必須這樣寫:
ifstream inputfile;
inutfile.open("input.txt");
也可以:
inutfile.open("input.txt", iso::in);
ios::in 開啟可供讀取資料的檔案
http://caterpillar.onlyfun.net/Gossip/CppGossip/UnFormatFileIO.html
111030_C_Array Subscripting
#include <stdio.h>
int main(void) {
int a[3] = { 10, 20, 30 };
printf("a[0] = %d\n", a[0]);
printf("a[1] = %d\n", 1[a]);
printf("a[2] = %d\n", *(2 + a));
return 0;
}
output:
a[0] = 10 a[1] = 20 a[2] = 30說明:int a[3] = { 10, 20, 30 };a其實是這個陣列的起始位址,所以 a[0] 相當於 *a ;那 a[1] 等同於 *(a + 1),對C語言來說,a[1] ≡ *(a + 1)。
基於加法可交換性,所以 *(a + 1) ≡ *(1 + a),
所以對C語言來說, a[1] ≡ *(1 + a) ≡ 1[a]...靠,這什麼鬼。參考:http://www.csie.ntu.edu.tw/~b94087/yap01_pointers_and_arrays.pdfhttp://blog-jy.blogspot.com/2006/11/array-subscripting-in-c.html
111029_演算法的特性
The properties of algorithm ?
1. Finiteness(有限性)
terminates after a finite number of steps
2. Definiteness(明確性)
rigorously and unambiguously specified
3. Input
valid inputs are clearly specified
4. Output
can be proved to produce the correct
output given a valid input
5. Effectiveness(有效性,可用紙筆計算)
basic steps are sufficiently simple and basic
2011年11月10日 星期四
111027_英文_一定成功的
surefire
[ˋʃuə͵faiə]
a.形容詞 一定成功的;不會失敗的
例句:
Surefire ways to make money from home.
讓您在家成功賺錢的方法
[ˋʃuə͵faiə]
a.形容詞 一定成功的;不會失敗的
例句:
Surefire ways to make money from home.
讓您在家成功賺錢的方法
111026_英文_考慮到,顧及到
take into account
考慮到,顧及到
例句:
We must take into account the gain of the antenna.
我們必須考慮到天線增益。
生字:
gain /gein/ 增加,增添
antenna /ænˋtenə/ 天線,觸角
考慮到,顧及到
例句:
We must take into account the gain of the antenna.
我們必須考慮到天線增益。
生字:
gain /gein/ 增加,增添
antenna /ænˋtenə/ 天線,觸角
2011年11月5日 星期六
111025_演算法_雙迴圈的時間複雜度
(a)
for(a=1; a<N; a++)
for(b=1; b<=N; b++)
c++;
解:
∑a=1N-1∑b=1N 1
= ∑a=1N-1.N
= N∑a=1N-11
= N(N-1)
≈ N2
∈ O(N2)
(b)
for(a=1; a<N; a++)
b++;
解:
∑a=1N-1 1 = N-1 ≈ N ∈ O(N)
(c)
for(a=1; a<N; a++)
for(b=a; b<7; b++)
c++;
解:
∑a=1N-1∑b=a 6 1
= ∑a=1N-1(6-a+1)
= ∑a=1N-1(7-a)
= 7∑a=1N-11 - ∑a=1N-1a
= 7(N-1-1+1) - (1+N-1)(N-1)/2
= 7(N-1) - N(N-1)/2
≈ N2
∈ O(N2)
for(a=1; a<N; a++)
for(b=1; b<=N; b++)
c++;
解:
∑a=1N-1∑b=1N 1
= ∑a=1N-1.N
= N∑a=1N-11
= N(N-1)
≈ N2
∈ O(N2)
(b)
for(a=1; a<N; a++)
b++;
解:
∑a=1N-1 1 = N-1 ≈ N ∈ O(N)
(c)
for(a=1; a<N; a++)
for(b=a; b<7; b++)
c++;
解:
∑a=1N-1∑b=a 6 1
= ∑a=1N-1(6-a+1)
= ∑a=1N-1(7-a)
= 7∑a=1N-11 - ∑a=1N-1a
= 7(N-1-1+1) - (1+N-1)(N-1)/2
= 7(N-1) - N(N-1)/2
≈ N2
∈ O(N2)
111024_等差級數之和
一等差級數 S = a1 + a2 + … + an,共n項
其和為 n(a1+an)/2
*要快速記憶的話,就把它想成一個梯形,梯形公式為上底加下底乘以高除2
所以S可以寫成 ∑k=1n ak 表示 a1 + a2 + … + an
其和為 n(a1+an)/2
*要快速記憶的話,就把它想成一個梯形,梯形公式為上底加下底乘以高除2
所以S可以寫成 ∑k=1n ak 表示 a1 + a2 + … + an
2011年11月4日 星期五
111023_JAVA_資料格式化
import java.io.*;
public class stuList {
static String pickName(String a){
a = a.substring(14, 25);
a = a.substring(0,a.indexOf(" "));
return a;
}
public static void main(String[] args) throws Exception {
FileReader liststu = new FileReader("c:\\stuMAIL.txt");
BufferedReader bufferListstu = new BufferedReader(liststu);
FileWriter wrFile = new FileWriter("c:\\output.txt");
BufferedWriter bw = new BufferedWriter(wrFile);
String nameList;
String outNameList;
String num;
while((nameList = bufferListstu.readLine())!=null){
num = nameList.substring(1, 10);
outNameList = num +",,"+ pickName(nameList)
+","+ num.toLowerCase() +"@ms1.uuu.edu.tw,,,3";
bw.write(outNameList);
bw.newLine();
}
bufferListstu.close();
bw.close();
}
}
public class stuList {
static String pickName(String a){
a = a.substring(14, 25);
a = a.substring(0,a.indexOf(" "));
return a;
}
public static void main(String[] args) throws Exception {
FileReader liststu = new FileReader("c:\\stuMAIL.txt");
BufferedReader bufferListstu = new BufferedReader(liststu);
FileWriter wrFile = new FileWriter("c:\\output.txt");
BufferedWriter bw = new BufferedWriter(wrFile);
String nameList;
String outNameList;
String num;
while((nameList = bufferListstu.readLine())!=null){
num = nameList.substring(1, 10);
outNameList = num +",,"+ pickName(nameList)
+","+ num.toLowerCase() +"@ms1.uuu.edu.tw,,,3";
bw.write(outNameList);
bw.newLine();
}
bufferListstu.close();
bw.close();
}
}
把原本的
"D10318002 ","吳XX ","d10318002@ms1.uuu.edu.tw"
"D10318003 ","歐XX ","d10318003@ms1.uuu.edu.tw"
"D10318004 ","蔡XX ","d10318004@ms1.uuu.edu.tw"
"D10318004 ","蔡XX ","d10318004@ms1.uuu.edu.tw"
...
改成
D10318002,,吳XX,d10318002@ms1.uuu.edu.tw,,,3
D10318003,,歐XX,d10318003@ms1.uuu.edu.tw,,,3
D10318004,,蔡XX,d10318004@ms1.uuu.edu.tw,,,3
111022_JAVA_把字串大小寫變小大寫
String toLowerCase()
例:
String a = "SUPERMAN";
String b = "batman";
System.out.println(a.toLowerCase());
System.out.println(b.toUpperCase());
輸出:
superman
BATMAN
例:
String a = "SUPERMAN";
String b = "batman";
System.out.println(a.toLowerCase());
System.out.println(b.toUpperCase());
輸出:
superman
BATMAN
2011年11月3日 星期四
111021_JAVA_從字串中抽取其中一段子字串
String substring(int beginIndex)
例:
String a = "superman";
System.out.println(a.substring(3)); //索引0,1,2不要,從索引3開始抽取
輸出:
erman
String substring(int beginIndex, int endIndex)
例:
String a = "superman";
System.out.println(a.substring(3, 6)); //從索引3抽取到索引6之前(所以索引6的值"a"不取,取至索引5"m"
輸出:
erm
例:
String a = "superman";
System.out.println(a.substring(3, 4)); //從索引3抽取到索引4之前(所以等於只抽取一字元
圖解:
0 1 2 3 4 5 6 7 8
s u p e r m a n \0
例:
String a = "superman";
System.out.println(a.substring(3)); //索引0,1,2不要,從索引3開始抽取
輸出:
erman
String substring(int beginIndex, int endIndex)
例:
String a = "superman";
System.out.println(a.substring(3, 6)); //從索引3抽取到索引6之前(所以索引6的值"a"不取,取至索引5"m"
輸出:
erm
例:
String a = "superman";
System.out.println(a.substring(3, 4)); //從索引3抽取到索引4之前(所以等於只抽取一字元
輸出:
e
e
圖解:
0 1 2 3 4 5 6 7 8
s u p e r m a n \0
訂閱:
文章 (Atom)