字串轉置

啊…腦袋裡python的語法還是記不得呀…
果然要有一本工具書…一個字串轉置就因為怎麼令一個矩陣來轉置都忘了。

以下參考其他人做法
def reverse(text):
    result = ""
    for idx in range(len(text) - 1, -1, -1):
        result += text[idx] #用於srting
    print result
    return result
def reverse(x):

    y = [ ]
    for n in x: 
        y.insert(0, n) #用於list

    y = "".join(y)   
    return str(y)

print reverse("text")   
 應該還可以使用.append()#用於list,來完成這個工作。

python 數字類別測試func.

1.整數測試: way 1: 利用math 模組測試 import math def is_int(x): if type(x) == int: return True else: return False way 2:利用round(),exp.:round(2.3) → 2 def is_int(x): if x == round(x): return True else: return False way 3:直接演算,取餘數 def is_int(x): if x%1 == 0: return True else: return False

2.質數測試
def is_prime(x):
    if x < 2:
        return False
    for n in range(2, x-1):
        if x % n == 0:
            return False
    else: 

        return True

http://tw.download.nvidia.com/XFree86/Linux-x86_64/310.40/README/installdriver.html


http://tw.download.nvidia.com/XFree86/Linux-x86_64/310.40/README/commonproblems.html#nouveau

http://www.cyberciti.biz/howto/debian-linux/install-nvidia-proprietary-unix-driver/

http://wiki.debian.org/NvidiaGraphicsDrivers#Install_the_kernel_module

http://www.cyberciti.biz/howto/debian-linux/install-nvidia-proprietary-unix-driver/

WMP IN CHROME


瀏覽器Chrome
安裝外掛套件後
沒有效
這時 檢查一下你的D槽或E槽
會有一個資料夾 PFiles\Plugins\np-mswmp.dll
把np-mswmp.dll 更名成NPMSWMP.dll
放到 “C:\Program Files (x86)\Windows Media Player\"下
重開google chrome後即可播放了。

debain 主機名稱修改

嗯..因為老師問我,怎麼把主機名稱"gauss"改成"Gauss"
傻了我@_@,因為我也不知道。
所以就查了一下,要怎麼改主機名稱
debain:
主機名稱是紀錄在
/etc/hostname
裡面,修改之後
/etc/init.d/hostname.sh start
登出再登入就會重新load hostname file了
不然就是重開機囉XP

cuda & openmp

nvcc file.cu -Xcompiler -fopenmp

OpenMP常遇到的問題

最近在學習OpenMP,基本上使用方法大概都可以由前一篇的文章連結學習到
不過小弟我在把我的code改成OpenMP的時候。速度卻比原本的慢了快100倍......
因此來把問題寫下...避免之後遇到不知道怎麼處理
1.rand()
rand()涵數是一個在global memory上執行的涵數,因此如果要在多個threads上同時執行。
rand()會有threads-safe的問題,所以在執行上會只淮許一個threads進去。

目前有兩個解決的方法
i。rand() → rand_r()
   drand48() → drand48_r()

Example: rand_r()

#pragma omp parallel firstprivate(a) num_threads(4)
  {
    unsigned int seed;  //threads_number_n(or other parameters)   
    seed = omp_get_thread_num();

    for(int i = 0;i< 100;i++){
    a = rand_r(&seed); 
      printf("threadnum = %d a = %f\n",omp_get_thread_num(),a);
      }
  } 


Example drand48_r()

#pragma omp parallel firstprivate(a) num_threads(4)
  {
    struct drand48_data drand_buf;
    unsigned short int x=0,y=0,z=0;
    long int see = 0;
    unsigned short int seed16v[3]={x,y,z};

    seed48_r(seed16v,&drand_buf);
    srand48_r(see,&drand_buf);
     //如此一來,四個threads都會是一樣的結果,記得seed48_r與srand48_r都要ini
     //否則結果會讓你很意外?      
    do{   
     
      for(int i = 0;i< 100;i++){
    drand48_r(&drand_buf,&a);     
      printf("threadnum = %d a = %f\n",omp_get_thread_num(),a);
      }   
#pragma omp barrier
#pragma omp single
      {
    txt++;
      }    
   }while(txt < 10);
  } 
參考文章
參考文章2


ii。另外尋找其他parallel random number generators
    → SPRNG  (還不會使用)
    → CUDA   (請查閱user guide)


2.malloc & free allocate (突然覺得我很雖...剛好都遇到了。_。)
其理由也是跟rand很像,他是直接把memory開在global memory上,因些無法直接分配給各個threads (不是很確定我這樣子解理對不對,畢竟對多執行緒還不是很了解)

以下是引述Jim Dempsey部落格裡的範例:
When you want each thread to have their own array
double* array = 0;   // *** bad, pointer in wrong scope
                     // ok to do this when shared(array) on pragma
#pragma omp parallel
{
    array = new double[count];  // *** bad all threads sharing same pointer
                                // *** 2nd and later threads overwrite pointer
   ...
   delete [] array; // *** 2nd and later threads returning same memory
}

------------------------------------

#pragma omp parallel
{
    double* array = 0;
    array = new double[count];  // *** good when you want each thread to have seperate copy
    ...
    delete [] array; // *** good each thread returning seperate copy
}

--------------------

double* array = 0; // OK because of private(array) on pragma
#pragma omp parallel private(array)
{
    array = new double[count];  // *** good when you want each thread to have seperate copy
    ...
    delete [] array; // *** good each thread returning seperate copy
}

--------------------

double* array = 0;
#pragma omp parallel private(array)
{
    array = new double[count];  // *** good when you want each thread to have seperate copy
    ...
}
delete [] array; // *** bad main thread returning one copy

There is nothing wrong with new/delete inside parallel regions, in fact it may be required when you want each thread to have seperate data (e.g. for temporary arrays).

原文連結

Example OpenMP

因為研究上的需要,因此開始學習OpenMP的語法,接下來的所有的文章皆是測試的文章心得

第一篇就用最簡單的教學吧

首先就是在GUN上要怎麼把OpenMP編譯進去

$ g++ filenamie.cpp -fopenmp
如果不加上-fopenmp的話,編譯器會自動把openmp的語法都忽略掉。

以下開始進行測試

#include
#include
#include
int main()
{
  for (int i = 0; i < 8; i++) {
    printf("thread [%d]: print number %d\n", omp_get_thread_num(), i);
  }
  return 0;
}

結果是:
thread [0]: print number 0
thread [0]: print number 1
thread [0]: print number 2
thread [0]: print number 3
thread [0]: print number 4
thread [0]: print number 5
thread [0]: print number 6
thread [0]: print number 7

omp_get_thread_num()語法是告知現在是那個執行緒,最簡單的想法就是他安排那一個CPU在跑這段語法
明顯看到,就是我們一般單執行緒的寫法。

接著加上openmp平行的寫法
#include
#include
#include
int main()
{
  #pragma omp parallel for
  for (int i = 0; i < 8; i++) {
    printf("thread [%d]: print number %d\n", omp_get_thread_num(), i);
  }
  return 0;
}

結果是:
thread [1]: print number 2
thread [1]: print number 3
thread [0]: print number 0
thread [0]: print number 1
thread [2]: print number 4
thread [2]: print number 5
thread [3]: print number 6
thread [3]: print number 7

可以看到,這個for變的不是單一執行緒在執行,而是不同的CPU在上面跑
所以出來的結果就不是如第一段相同。

最後再來看看
#include
#include
#include
int main()
{
  #pragma omp parallel
  for (int i = 0; i < 8; i++) {
    printf("thread [%d]: print number %d\n", omp_get_thread_num(), i);
  }
  return 0;
}

結果會是:
thread [2]: print number 0
thread [2]: print number 1
thread [2]: print number 2
thread [2]: print number 3
thread [2]: print number 4
thread [2]: print number 5
thread [2]: print number 6
thread [2]: print number 7
thread [1]: print number 0
thread [1]: print number 1
thread [1]: print number 2
thread [1]: print number 3
thread [1]: print number 4
thread [1]: print number 5
thread [1]: print number 6
thread [1]: print number 7
thread [3]: print number 0
thread [3]: print number 1
thread [3]: print number 2
thread [3]: print number 3
thread [3]: print number 4
thread [3]: print number 5
thread [3]: print number 6
thread [3]: print number 7
thread [0]: print number 0
thread [0]: print number 1
thread [0]: print number 2
thread [0]: print number 3
thread [0]: print number 4
thread [0]: print number 5
thread [0]: print number 6
thread [0]: print number 7

目前就先寫到這,因為還有很多不懂的地方


學習參考文章:
VIML
OpenMP并行程序设计(二)
任務的劃分 
變數環境 

visual profiler V3.2 on debian

本來想用visual profiler看一下程式上還有那邊可以修改的
沒想到v3.2的cuda toolkit竟然開不了!出現缺少
GLIBCXX_3.4.11 not found (required by computeprof)

突然就傻了,之前記得是可以用的
然後跑去NVIDIA的論壇看看,找到解答了
解決辦法
不過我還是自已寫一遍下來吧,以後要用可以翻比較快
1.
$/usr/local/cuda/computeprof/bin/computeprof &
$computeprof: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by computeprof)

如果出現上面的訊息
先到debain的網站下載libstdc++.so.6
debian官方網站

2.
#dpkg -x libstdc++6_4.4.4-8_amd64.deb /tmp
#cp /tmp/usr/lib/libstdc++.so.* /usr/local/cuda/computeprof/bin/

這樣一來就應該可以使用了

flash player for 64bit linux

看來終於可以在linux 64bit上使用flash player
(也有可能是小弟之前愚笨不知道怎麼使用)

目前在阿多比的官網並沒有提供64bit的下載
可是到阿多比的lab 可以找到flash player Square
flashplayer10_square
下載下來吧!for linux 64bit

#tar zxvf flashplayer10_2_p3_64bit_linux_111710.tar.gz
#mv  libflashplayer.so /usr/lib64/iceweasel/plugins
#chmod 755 libflashplayer.so
#chown user:user libflashplayer.so

然後重新啟動iceweasel
上youtube看看吧!ok了

另外補充一下
如果要換新版本的square
要手動刪掉/usr/lib64/iceweasel/plugins裡的libflashplayer.so
再重覆上面的動作。

字型篇

打算開始寫這一系列的文章,原因是因為白底黑字的預設值,讓我看久了眼睛好酸...
還有那密密麻麻的字型.......會讓人家發瘋呀!!!!
參考文章: Emacs字体设置

第一篇先來說怎麼改字型吧....

1. #emacs /etc/X11/xorg.conf
Section "Module"
         ......
         Load "freetype"
         ......
EndSection
Section "Files"
         ......
         FontPath "/usr/share/fonts/truetype/"
         ......
EndSection
2.restart Xwindow
3.xlsfonts |grep (想用的字型)
例如:
Landau:/home/zcli# xlsfonts |grep inconsolata
-unknown-inconsolata-medium-r-normal--0-0-0-0-c-0-iso10646-1
-unknown-inconsolata-medium-r-normal--0-0-0-0-c-0-iso8859-1
-unknown-inconsolata-medium-r-normal--0-0-0-0-c-0-iso8859-15
-unknown-inconsolata-medium-r-normal--0-0-0-0-m-0-iso10646-1
-unknown-inconsolata-medium-r-normal--0-0-0-0-m-0-iso8859-1
-unknown-inconsolata-medium-r-normal--0-0-0-0-m-0-iso8859-15
4.改成如下
-unknown-inconsolata-medium-r-normal--*-*-*-*-m-*-fontset-inconsolata
注意,用 xlsfonts 列出来的字体名称中,有些字段为 0,这些是可缩放的向量
字体,这些 0 不能保留,必须用数字或 `*' 号取代 
不過建議是用fixed字體來編寫程式會比較合適
 
方法1:啟動時加入
 
1.#emacs ~/.emacs
(create-fontset-from-fontset-spec
 (concat
  "-unknown-inconsolata-medium-r-normal--*-*-*-*-m-*-fontset-inconsolata,"
  "chinese-gb2312:-*-simsun-medium-r-*-*-14-*-*-*-c-*-gb2312*-*,"
  "mule-unicode-0100-24ff:-*-simsun-medium-r-*-*-14-*-*-*-c-*-iso10646*-*,"
  "korean-ksc5601:-*-*-medium-r-*-*-14-*-*-*-*-*-ksc5601*-*,"
  "chinese-cns11643-5:-*-simsun-medium-r-*-*-14-*-*-*-c-*-gbk*-*,"
  "chinese-cns11643-6:-*-simsun-medium-r-*-*-14-*-*-*-c-*-gbk*-*,"
  "chinese-cns11643-7:-*-simsun-medium-r-*-*-14-*-*-*-c-*-gbk*-*,"
  "sjis:-*-medium-r-normal--14-*-jisx0208*-*"))
後面各段格式都是『字符集:字體』
第一段是指定ASCII英文字型
第二段則是中文也就是gb2312的字型
 
2.(set-default-font "fontset-inconsolata")
 
3.(setq default-frame-alist
      (append
       '((font . "fontset-inconsolata")) default-frame-alist))
 
方法2:寫入defaults
1.#emacs ~/.Xdefaults
 Emacs.Fontset-0:-unknown-inconsolata-medium-r-normal--*-*-*-*-m-*-fontset-inconsolata,\
 chinese-gb2312:-*-simsun-medium-r-*-*-14-*-*-*-c-*-*-*,\
 mule-unicode-0100-24ff:-*-simsun-medium-r-*-*-14-*-*-*-c-*-iso10646*-*,\
 korean-ksc5601:-*-*-medium-r-*-*-14-*-*-*-*-*-ksc5601*-*,\
 chinese-cns11643-5:-*-simsun-medium-r-*-*-14-*-*-*-c-*-gbk*-*,\
 chinese-cns11643-6:-*-simsun-medium-r-*-*-14-*-*-*-c-*-gbk*-*,\
 chinese-cns11643-7:-*-simsun-medium-r-*-*-14-*-*-*-c-*-gbk*-*,\
 sjis:-*-medium-r-normal--14-*-jisx0208*-*
 
 Emacs.font: fontset-inconsolata
 
2.# xrdb -merge ~/.Xdefaults
PS.要解除defaults的話就
# xrdb -remove ~/.Xdefaults 
 
Emacs 23 ( 我直接貼上來的...因為Debain目前只到22...留著參考)
Emacs23的字体设置与上述方法类似,但也有所不同。或许是因为emacs23的实现 比较独特,或许是emacs23的bug,按上述方法指定的中文字体无法起作用。因此, emacs23的字体设置采用下述方法:
仍然采用 create-fontset-from-fontset-spec 创建 fontset:
(create-fontset-from-fontset-spec "-*-courier-medium-r-normal-*-14-*-*-*-*-*-fontset-courier") (set-default-font "fontset-courier") (setq default-frame-alist (append '((font . "fontset-courier")) default-frame-alist))
也可以在 ~/.Xdefaults 中这样设置:
Emacs.Fontset-0:-*-courier-medium-r-normal-*-14-*-*-*-*-*-fontset-courier Emacs.font:fontset-courier
两种方法取其一即可。 

但是设置中文字体时,采用 set-fontset-font 分别指定各种 script 的字体:
(set-fontset-font "fontset-default" nil "-*-simsun-*-*-*-*-14-*-*-*-*-*-gb2312.1980-*" nil 'prepend) (set-fontset-font "fontset-courier" 'kana "-*-simsun-*-*-*-*-14-*-*-*-*-*-gbk-0" nil 'prepend) (set-fontset-font "fontset-courier" 'han "-*-simsun-*-*-*-*-14-*-*-*-*-*-gbk-0" nil 'prepend) (set-fontset-font "fontset-courier" 'cjk-misc "-*-simsun-*-*-*-*-14-*-*-*-*-*-gbk-0" nil 'prepend)
 

Debian 字型

首先還是要把參考文章列出來:
Tsung's Blog
其實一開始是想把Debain的字型換成unbuntu的那種,也就是『Monaco Font』
首先就是下載字型吧 : Return of Monaco.ttf 

# cp monaco.ttf /usr/share/fonts/truetype/
# fc-cache -f -v  

然後就可以切換字型了
另外Tsung的文中還有提到其他好用的字型:
1.Debian 也新推出一個 Terminal 專用字型(apt-get install ttf-inconsolata)
2.Consolas
3.另外也記一下種Debain用的terminal字型(apt-get install xfonts-terminus)
Tsung言:
PS: 想挑字型太累, 可以: apt-get install gnome-specimen , 用 gnome-specimen 來挑喜歡的字型來用比較快唷

另外,一些中文字型的設定可以參考下面這篇文章!真的是寫的超好的
http://wiki.ubuntu-tw.org/index.php?title=UbuntuL10n
Debainfonts
fontconfig

有要看的文章:
如何裝ms字型

掛載隨身硬碟的好工作!

就是你了!還看!

ntfs-3g

當debain不會自動掛載隨身碟的時候…
就要靠它啦!

#apt-get install ntfs-3g

commond:
mount
ntfs-3g /dev/sda1 /mnt/windows
unmonut
umount /mnt/windows

剩下其他指令可以查看
http://linux.die.net/man/8/mount.ntfs-3g
最後給自已一個tip
-o locale=zh_TW.utf8 (繁中)
-o locale=zh_CH.utf8 (簡中)
如此一來,沒辦法顯示中文的問題就解決了

ntfs-3g /dev/hda1 /windows/C/ -o silent,umask=0,locale=zh_TW.utf8

搞不懂的ubutnu

拿ubuntu的source.list安裝一些東西,結果debian不能上網了.......
好像root端被殺了.............. 
先不談拿ubuntu的apt來玩debian這件事 
我了解到一件事
原來main之前的單字表示版本>"< 所以說要找不同版本的東西,就改source.list就可以了
10.4
deb http://tw.archive.ubuntu.com/ubuntu/ lucid main universe restricted multiverse
deb http://tw.archive.ubuntu.com/ubuntu/ lucid-updates universe main multiverse restricted
deb http://tw.archive.ubuntu.com/ubuntu/ lucid-proposed universe main multiverse restricted
deb http://tw.archive.ubuntu.com/ubuntu/ lucid-security universe main multiverse restricted
deb http://tw.archive.ubuntu.com/ubuntu/ lucid-backports main multiverse restricted universe
deb-src http://tw.archive.ubuntu.com/ubuntu/ lucid main universe restricted multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu/ lucid-security universe main multiverse restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ lucid-updates universe main multiverse restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ lucid-proposed universe main multiverse restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ lucid-backports universe main multiverse restricted
9.10

# 國家高速網路與計算中心
deb ftp://os.nchc.org.tw/ubuntu karmic-updates main restricted universe multiverse
deb ftp://os.nchc.org.tw/ubuntu karmic main universe multiverse restricted
deb ftp://os.nchc.org.tw/ubuntu karmic-backports main universe multiverse restricted
deb ftp://os.nchc.org.tw/ubuntu karmic-proposed main universe multiverse restricted
deb ftp://os.nchc.org.tw/ubuntu karmic-security main restricted universe multiverse
deb ftp://os.nchc.org.tw/ubuntu karmic-proposed main universe multiverse restricted
deb ftp://os.nchc.org.tw/ubuntu karmic-security mai
 
9.04 
deb http://gb.archive.ubuntu.com/ubuntu/ jaunty universe
deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty universe
deb http://gb.archive.ubuntu.com/ubuntu/ jaunty-updates universe
deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty-updates universe
 

讓我的"大"A6耳機有聲音

看來許多華碩A系列產品都有這個問題,耳機沒有聲音。
目前測試 debain505 i386
#atp-get install alsa-utils
把以下文字
options snd-hda-intel model=z71v position_fix=1
貼到:
/etc/modprobe.d/alsa-base
看論壇ubuntu要貼到
/etc/modprobe.d/sound

重新開機,搞定!

debian 6
貼到
/etc/modprobe.d/alsa-base
/etc/modprobe.d/alsa-base.conf
/etc/modprobe.d/sound

reboot

linux 常用的播放器

兩個好用的linux音樂播放器

Amarok

Exaile

兩個都非常不錯,而且apt就有了,方便又好用的東西

另外下面留給.......影音播放器>"< 目前還找不到比較好又方便的播放器 不過目前用的Mplayer,debain原有的播放器 想看rmvb可以參考以下網頁

以下內容取自 How to play rmvb in mplayer

This tutorial will take you step by step through installing all of the software necessary to play rmvb (RealMedia Variable Bitrate) files in Ubuntu Linux.
Though the steps and screenshots are specific to Ubuntu, they will likely be similar for other versions of Linux. With that said, be sure to read the MPlayer README file if you’re not using Ubuntu. Similar to some of the other tutorials on Simplehelp, this is almost certainly not the only way to play .rmvb files in Ubuntu, but it’s the easiest way I could find. If you know of a easier method, by all means please feel free to leave a comment.
  1. The first step in playing .rmvb files in Ubuntu is to use the Synaptic Package Manager to install MPlayer. When you mark MPlayer for installation, you’ll be prompted to install additional software packages (if they’re not already installed).
  2. play rmvb files in ubuntu linux click to enlarge
  3. After MPlayer has been installed, exit out of the Synaptic Package Manager and visit the MPlayer binary codec download page. Download the codec package for your platform (for example, if you’re using a 32bit Intel or AMD processor, download the Linux x86 package). Save the file to your desktop (or home folder). Once the download has completed, double-click that file. Select the folder to uncompress, and click the Extract button.
    play rmvb files in ubuntu linux
    click to enlarge

  4. Choose a location to extract the files (your desktop is ideal) and again click Extract.
  5. play rmvb files in ubuntu linux click to enlarge
  6. Make sure the files extracted correctly. They’ll be in a folder titled essential-date.
  7. play rmvb files in ubuntu linux
  8. Open up a Terminal by selecting Applications -> Accessories -> Terminal.
  9. play rmvb files in ubuntu linux
  10. Enter the following commands (and your password when prompted):
    cd Desktop
    cd essential-date
    sudo mkdir /usr/lib/codecs
    sudo cp * /usr/lib/codecs
  11. play rmvb files in ubuntu linux click to enlarge
  12. NOTE: you may need to install libstdc++5 to get .rmvb files to play. Even though it might not be necessary for you, it can’t hurt to install (the package isn’t very big). Run the command: sudo apt-get install libstdc++5 in a Terminal, or use Synaptic and search for libstdc++5. Thanks to everyone who commented (see comments below) for the tip.
  13. Launch MPLayer by selecting Applications -> Sound & Video -> MPlayer Movie Player. Right-click in the Mplayer – Video window and select Preferences from the menu.
  14. play rmvb files in ubuntu linux
  15. Select the Video tab and change the Available drivers: to x11 X11 (XImage/Shm).
  16. play rmvb files in ubuntu linux click to enlarge
  17. Select the Codecs & demuxer tab and change the Video codec family: to RealVideo decoder and the Audio codec family: to FFmpeg/libavcodec audio decoders. When you’re done, click OK and close down MPlayer.
  18. play rmvb files in ubuntu linux click to enlarge
  19. Locate one of your .rmvb files, right-click it and select Properties.
  20. play rmvb files in ubuntu linux
  21. Select the Open With tab and change whatever the default is to MPlayer Movie Player. Click Close.
  22. play rmvb files in ubuntu linux click to enlarge
  23. Double-click any of your .rmvb files and they should open up in MPlayer and start playing.
  24. play rmvb files in ubuntu linux

linux 掛載光碟

#apt-get install fuseiso

#mkdir DVDISO //創造任意一個資料夾

#fuseiso DVD.iso DVDISO //掛載到DVDISO

#cd DVDISO

#fusermount -u DVDISO //卸載

c語言常用IO參數

%d %i 十進位整數
%u unsigned 十進位整數
%x unsigned 16進位整數,小寫表示(a-f)
%X unsigned 16進位整數,大寫表示(A-F)
%o unsigned 8進位整數
以上加-和數字表示左對齊最少幾位,如%-9d表示左切齊最少印9位
以上加+和數字表示右對齊最少幾位,如%+9d表示右切齊最少印9位,不足處補空白
以上加+和0開頭的數字表示右對齊最少幾位,不足補0,如%+09d表示右切齊最少印9位,不足處補0
%ld 以十進位印出long
%lld 以十進位印出long long
%f浮點數float
%e %E科學表示法浮點數double,%e小寫 %E大寫
%g %G依照double的數值自動選擇以%f或%e格式印出
以上加-和具有小數點的數字表示左對齊最少幾位,如%-9.2f表示左切齊最少印9位,其中小數點以下2位
以上加+和具有小數點的數字表示右對齊最少幾位,如%=9.2f表示右切齊最少印9位,其中小數點以下2位
%c unsigned char
%s string(array of char terminated by 0)
%p pointer to void
%% 印出%

用C來寫複數

GNU C99以前通常是用結構(struct)來表示,簡單的例子如下
------------------------------------------------------ 
#include < stdio.h >

struct my_complex {
double real;
double imag;
};
int main(void){
struct my_complex z = {42.0, 42.0};

printf("z = %f + %fI\n",x.real, x.imag);

return 0;
}
-----------------------------------------------------
C99提供了一個方便的表示方法,在complex.h裡面
#include < stdio.h >
#include < complex.h >
int main (void){
complex double z = 42.0 + 42.0*I;

printf("z = %f + %fI\n", creal(z), cimag(z));

return 0;
}
----------------------------------------------------- 
— Function: double creal (complex double z) 
— Function: float crealf (complex float z) 
— Function: long double creall (complex long double z)These functions return the real part of the complex number z.
— Function: double cimag (complex double z) 
— Function: float cimagf (complex float z) 
— Function: long double cimagl (complex long double z)These functions return the imaginary part of the complex number z.
 
詳細的內容可以參考:
http://www.gnu.org/s/libc/manual/html_node/Complex-Numbers.html#Complex-Numbers 

apt 常用指令

本文取自:http://plog.longwin.com.tw/my_note-unix/2005/05/01/use_apt

伺服器列表
/etc/apt/source.list

系統升級相關:
  • apt-get upgrade => 軟體升級
  • apt-get dist-upgrade => 系統升級
  • 更多詳細可見: SoftwareUpgrading
=======
aptitude
=======
1.aptitude install套件名稱
單純安裝指定套件

其他的可以參考apt-get
=======
apt-get
=======
1.apt-get update
更新套件資訊,要升級之前,最好都先執行一次本指令和 Server 端的資訊同步一下

2.apt-get check
檢查你系統上套件的相依性狀況

3.apt-get dist-upgrade 和 apt-get upgrade
執行整個升級動作,建議用 apt-get dist-upgrade 比較好

4.apt-get install 套件名稱
安裝某一個套件及其相關的套件

5.apt-get remove 套件名稱 (含設定檔等完整移除: apt-get --purge remove 套件名稱)
移除某套件,和 rpm -e 功能一樣,同時還會幫您把相關的套件一併移除

6.apt-get source 套件名稱
抓回 source rpm
例: apt-get source --compile zhcon
抓回 source rpm 並編譯成 binary rpm
--compile 參數就如同 rpm -ba 一般

7.apt-get clean
刪除下載回來的檔案
=========
apt-cache
=========
1.apt-cache showpkg
顯示套件資訊
例: apt-cache showpkg zhcon

2.apt-cache stats
顯示相關的統計資訊

3.apt-cache dump
顥示 cache 中每個套件的簡短資訊

4.apt-cache unmet
檢查所有未符合相依性的相關資訊

5.apt-cache show
顯示套件資訊,同 rpm -qi 一般

6.apt-cache search
尋找檔案  例: apt-cache search zhcon

7.apt-cache depends
顯示套件的相依性  例: apt-cache depends zhcon

8.apt-cache pkgnames
尋找符合的套件名稱  例: $ apt-cache pkgnames openss
openssh-askpass
openssl096
openssl-perl
openssl095a
openssl-python
openssh-clients
openssl-devel
openssh-askpass-gnome
openssh
openssl
openssh-serve


==========
apt-config
==========
1.apt-config dump
顯示目前的設定狀態

參考
http://www.linux.org.tw/~candyz/APT-HOWTO_CLE.txt
http://www.debian.org/doc/manuals/apt-howto/ 
其它備註
  • 移除多餘套件(Library): apt-get remove --purge `deborphan`

------------------------------------------------------------------
apt-get install package --reinstall 重新安裝套件
apt-get -f install 修復安裝 "-f = --fix-missing"
apt-cache rdepends package 是查看該套件被哪些套件依賴
apt-get build-dep package 安裝相關的編譯環境
apt-get source package 下載該套件的原始碼
apt-get clean && apt-get autoclean 清理沒用的套件
apt-get check 檢查是否有損壞的相依性
------------------------------------------------------------------
aptitude
套件管理程式,不喜歡打上述指令可以用這個。