2001-01-01から1年間の記事一覧

『明解C言語 入門編』in Python

『明解C言語 入門編』 in Python 柴田望洋『明解C言語 入門編』を Python で実装してみます。 1. まずは慣れよう 000.整数値 15 と 37 の和を表示する 001.整数値 15 から 37 を引いた値を表示する 002.整数値 15 と 37 の和を親切に表示する 003.2つの変…

ポインタのソート

明解C言語 入門編 > 12. 構造体 > ポインタのソート Python # coding: Shift_JIS NINSU = 5 def compare_height(x, y): if (x["height"] > y["height"]): return 1 if (x["height"] < y["height"]): return -1 return 0 def compare_weight(x, y): if (x["w…

構造体の動的配列 (realloc)

明解C言語 入門編 > 12. 構造体 > 構造体の動的配列 (realloc) Python

構造体の動的配列 (malloc)

明解C言語 入門編 > 12. 構造体 > 構造体の動的配列 (malloc) Python # coding: Shift_JIS NINSU = 5 def compare_height(x, y): if (x["height"] > y["height"]): return 1 if (x["height"] < y["height"]): return -1 return 0 def compare_weight(x, y):…

5人の学生を 身長・体重で ソート (関数ポインタ)

明解C言語 入門編 > 12. 構造体 > 5人の学生を 身長・体重で ソート (関数ポインタ) Python # coding: Shift_JIS NINSU = 5 def compare_height(x, y): if (x["height"] > y["height"]): return 1 if (x["height"] < y["height"]): return -1 return 0 def…

5人の学生を 身長で ソート (構造体)

明解C言語 入門編 > 12. 構造体 > 5人の学生を 身長で ソート (構造体) Python # coding: Shift_JIS NINSU = 5 def sort(data, n): k = n - 1 while (k >= 0): j = -1; for i in range(1, k + 1, 1): if (data[i - 1]["height"] > data[i]["height"]): j =…

構造体を返す関数

明解C言語 入門編 > 12. 構造体 > 構造体を返す関数 Python

構造体と typedef

明解C言語 入門編 > 12. 構造体 > 構造体と typedef Python

-> 演算子

明解C言語 入門編 > 12. 構造体 > -> 演算子 Python

構造体の受け渡し

明解C言語 入門編 > 12. 構造体 > 構造体の受け渡し Python # coding: Shift_JIS def hiroko(std): std["height"] = 180; std["weight"] = 80; sanaka = {"name":"Sanaka", "height":175} print "氏名:%s" % sanaka["name"] print "身長:%d" % sanaka["he…

構造体のメンバの初期化

明解C言語 入門編 > 12. 構造体 > 構造体のメンバの初期化 Python # coding: Shift_JIS sanaka = {"name":"Sanaka", "height":175, "weight":60.5} print "氏名:%s" % sanaka["name"] print "身長:%d" % sanaka["height"] print "体重:%f" % sanaka["wei…

構造体

明解C言語 入門編 > 12. 構造体 > 構造体 Python # coding: Shift_JIS sanaka = {} sanaka["name"] = "Sanaka"; sanaka["height"] = 175; sanaka["weight"] = 60.5; print "氏名:%s" % sanaka["name"] print "身長:%d" % sanaka["height"] print "体重:%…

5人の学生を 身長で ソート (配列)

明解C言語 入門編 > 12. 構造体 > 5人の学生を 身長で ソート (配列) Python # coding: Shift_JIS NINSU = 5 def sort(height, name, n): k = n - 1 while (k >= 0): j = -1; for i in range(1, k + 1, 1): if (height[i - 1] > height[i]): j = i - 1 hei…

5人の学生の身長を ソート

明解C言語 入門編 > 12. 構造体 > 5人の学生の身長を ソート Python # coding: Shift_JIS NINSU = 5 def sort(data, n): k = n - 1 while (k >= 0): j = -1; for i in range(1, k + 1, 1): if (data[i - 1] > data[i]): j = i - 1 data[i], data[j] = data…

さまざまな文字列操作

明解C言語 入門編 > 11. 文字列とポインタ > さまざまな文字列操作 Python

指定した文字数だけ、文字列をコピー

明解C言語 入門編 > 11. 文字列とポインタ > 指定した文字数だけ、文字列をコピー Python

文字列のコピー

明解C言語 入門編 > 11. 文字列とポインタ > 文字列のコピー Python

文字列の長さを調べる

明解C言語 入門編 > 11. 文字列とポインタ > 文字列の長さを調べる Python

「配列で実現する文字列」の配列と、「ポインタで実現する文字列」の配列

明解C言語 入門編 > 11. 文字列とポインタ > 「配列で実現する文字列」の配列と、「ポインタで実現する文字列」の配列 Python

配列で実現する文字列と、ポインタで実現する文字列との、違い (文字列の代入)

明解C言語 入門編 > 11. 文字列とポインタ > 配列で実現する文字列と、ポインタで実現する文字列との、違い (文字列の代入) Python

配列で実現する文字列と、ポインタで実現する文字列との、共通点

明解C言語 入門編 > 11. 文字列とポインタ > 配列で実現する文字列と、ポインタで実現する文字列との、共通点 Python

配列で実現する文字列と、ポインタで実現する文字列

明解C言語 入門編 > 11. 文字列とポインタ > 配列で実現する文字列と、ポインタで実現する文字列 Python

配列の受け渡し

明解C言語 入門編 > 10. ポインタ > 配列の受け渡し Python

配列とポインタ

明解C言語 入門編 > 10. ポインタ > 配列とポインタ Python

2つの値を交換する

明解C言語 入門編 > 10. ポインタ > 2つの値を交換する Python # coding: Shift_JIS def swap1(nx, ny): tmp = nx nx = ny ny = tmp def swap2(nx, ny): return ny, nx na = 57 nb = 21 print "整数A:%d" % na print "整数B:%d" % nb print swap1(na, …

大文字・小文字の変換

明解C言語 入門編 > 9. 文字列の基本 > 大文字・小文字の変換 Python # coding: Shift_JIS str = "BohYoh" str = str.upper() print "大文字:", str str = str.lower() print "小文字:", str 実行結果 N:\>python lesson_09_076.py 大文字: BOHYOH 小文…

文字列の配列を受け渡し

明解C言語 入門編 > 9. 文字列の基本 > 文字列の配列を受け渡し Python def put_strary(st, n): for i in range(n): print "st[%d] = \"%s\"" % (i, st[i]) cs = ["Turbo", "NA", "DOHC"] n = 3 put_strary(cs, n) 実行結果 N:\>python lesson_09_075.py st…

文字列内の数字の出現回数を数える

明解C言語 入門編 > 9. 文字列の基本 > 文字列内の数字の出現回数を数える Python cnt = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] str = "3.1415926535897932846" for i in range(len(str)): char = str[i] if (("0" <= char) and (char <= "9")): cnt[int(char)] +…

文字列の走査

明解C言語 入門編 > 9. 文字列の基本 > 文字列の走査 Python import sys def put_string(str): for i in range(0, len(str), 1): sys.stdout.write(str[i]) str = "ABC" put_string(str) print 実行結果 N:\>python lesson_09_073.py ABC

文字列の長さを調べる

明解C言語 入門編 > 9. 文字列の基本 > 文字列の長さを調べる Python # coding: Shift_JIS n = len("123") print "バイト('123') = %d" % n n = len(u"123") print "文字数('123') = %d" % n 実行結果 N:\>python lesson_09_072.py バイト('1…