- ヘッダーファイル str2int.h が必要です。
#include "str2int.h"
のように使ってください。 - C言語で
*(str++)
というのはstr[i++]
のようなものです。 (c = str[i++]) != EOF
はstr[i]
を c に代入しi++
を実行しc
の値がEOF
に等しくないか比較します。
- したがって
while ((c = str[i++]) != EOF) { ... }
は,「str
から1文字ずつ取得しループする。EOF になったら終了。」という意味です。 - オートマトンのプログラムを作る流儀はいくつかありますが,状態遷移とは,つきつめると gotoであり,gotoで移動しながら処理を進めるプログラムを示します。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Table | |
class KeyValue | |
# creates instance variables @key and @value; | |
# defines getter / setter as name as obj.key and obj.value (note: no '@') | |
attr_accessor :key, :value | |
# KeyValue.new(key, value) creates a new instance | |
def initialize(key, value) | |
@key, @value = key, value | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Description: A Scala implementation of a parser for integer literals | |
// | |
package string2int | |
// The states of the parser | |
enum State { case START, ZERO, DEC, OCT, B, BIN, X, HEX, ERROR } | |
import State._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
size(500, 500); | |
noLoop(); | |
} | |
void draw() { | |
stroke(#ffffff); | |
strokeWeight(20); | |
snow(width/2, height/2, 0.8 * min(width, height)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
size(500, 500); | |
noLoop(); | |
} | |
void draw() { | |
translate(width/2, 0.9 * height); | |
scale(1, -1); | |
tree(0.8 * height, 5); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections.abc import Mapping, MutableMapping | |
class Table(MutableMapping): | |
def __init__(self): | |
self.__table = [] # the internal table as a list of key-value pairs | |
def __len__(self): | |
return len(self.__table) | |
def __str__(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Reader; | |
import java.io.StringReader; | |
import java.io.IOException; | |
import static java.lang.Character.isDigit; | |
enum State { START, ZERO, DEC, OCT, X, HEX } | |
public class String2int { | |
public static int string2int(String digits) { | |
return (int)string2long(digits); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <ctype.h> | |
int e_atoi(char *str) { | |
enum { ST_START, ST_ZERO, ST_DEC, ST_OCT, ST_X, ST_HEX } state = ST_START; | |
int result = 0; | |
for (int c = *(str++); c != '\0'; c = *(str++)) { | |
switch (state) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable | |
class HashTable[K, V](n: Int) extends mutable.AbstractMap[K, V] { | |
protected var table = mutable.ArraySeq.fill(n)(Nil:List[(K, V)]) | |
protected var count = 0 | |
def this() = this(10) | |
override def size: Int = count |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class HashTable<K, V> extends AbstractMap<K, V> { | |
protected SimpleEntry<K, V>[] table_; | |
protected int count_ = 0; | |
private HashTable<K, V> self = this; | |
public HashTable(int n) { | |
table_ = (SimpleEntry<K, V>[])new SimpleEntry[n]; | |
} |
NewerOlder