Created
June 14, 2012 08:32
-
-
Save tdkn/2929043 to your computer and use it in GitHub Desktop.
kadai 20120614
This file contains 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 <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
int main(void) { | |
int i=0,j=0,k=0; | |
int tmp=0; | |
int map[5][5]={0},buf[5][15]={0}; | |
srand((unsigned int) time(NULL)); | |
// 配列に1-75の値を格納 | |
for(i=0; i<5; i++) { | |
for(j=0; j<15; j++) { | |
buf[i][j] = k + 1; | |
k++; | |
} | |
} | |
// 2次配列をシャッフル | |
for(i=0; i<5; i++) { | |
for(j=14; j; j--) { | |
tmp = buf[i][j]; | |
k = rand() % (j + 1); | |
buf[i][j] = buf[i][k]; | |
buf[i][k] = tmp; | |
} | |
} | |
puts(" B I N G O "); | |
// ビンゴカードを描画 | |
for(i=0; i<5; i++) { | |
for(j=0; j<5; j++) { | |
if(i == 2 && j == 2) { | |
printf(" "); | |
} else { | |
printf("%3d", map[i][j]=buf[j][i]); | |
} | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
This file contains 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
#!/bin/bash | |
# ビンゴカードをHTMLで整形して出力 > ファイル | |
# firefox file.html | |
# delete contents | |
echo '' > bingo.html | |
# html out | |
echo '<!doctype html> | |
<meta charset="UTF-8"> | |
<style> | |
table { | |
text-align: center; | |
margin: 0px auto; | |
font-size: x-large; | |
border: 2px solid #ccc; | |
border-collapse: collapse; } | |
td, th { | |
border: 2px solid #ccc; } | |
</style> | |
<title>bingo sheet</title> | |
<table>' > bingo.html | |
# rendering bingo table | |
if [ -x ./bingo ]; then | |
./bingo | awk ' | |
(NR == 1) { | |
print "<tr><th>"$1"</th><th>"$2"</th><th>"$3"</th><th>"$4"</th><th>"$5"</th></tr>" } | |
(NR != 1 && NR != 4) { | |
print "<tr><td>"$1"</td><td>"$2"</td><td>"$3"</td><td>"$4"</td><td>"$5"</td></tr>" } | |
(NR == 4) { | |
print "<tr><td>"$1"</td><td>"$2"</td><td></td><td>"$3"</td><td>"$4"</td></tr>" | |
}' >> bingo.html | |
echo '</table>' >> bingo.html | |
/usr/bin/firefox bingo.html & | |
else | |
echo "bingo program not found." | |
fi |
This file contains 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
#!/bin/bash | |
# 住所 => 郵便番号 | |
echo '*住所 => 郵便番号 検索*' | |
if [ -f KEN_ALL.CSV ];then | |
echo -n '都道府県: ' | |
read T | |
echo -n '市区町村: ' | |
read S | |
echo -n '町域: ' | |
read C | |
if [ "$T" != "" ] && [ "$S" != "" ] && [ "$C" != "" ];then | |
cat KEN_ALL.CSV |grep "$T" |grep "$S" |grep "$C"| cut -d',' -f3 | |
echo '検索が終了しました.' | |
exit 0 | |
else | |
echo 'エラー: 無効なクエリです.' | |
exit 1 | |
fi | |
else | |
echo 'エラー: "KEN_ALL.CSV" がみつかりません.' | |
exit 1 | |
fi |
This file contains 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
#!/bin/bash | |
# 郵便番号 => 住所 | |
echo '*郵便番号 => 住所 検索*' | |
echo -n '郵便番号: ' | |
QUERY="" | |
if [ -f KEN_ALL.CSV ]; then | |
read QUERY | |
if [ "$QUERY" != "" ]; then | |
if [ -z `echo $QUERY | egrep '^[0-9]{7}$'` ]; then | |
echo '無効なクエリです.' | |
exit 1 | |
else | |
cat KEN_ALL.CSV | grep "$QUERY" | cut -d',' -f7,8,9 | |
echo '検索が終了しました' | |
exit 0 | |
fi | |
else | |
echo '' | |
echo '使い方' | |
echo ' 郵便番号: 9000000 (7ケタ)' | |
exit 1 | |
fi | |
else | |
echo 'error: "KEN_ALL.CSV" not found.' | |
exit 1 | |
fi |
This file contains 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
#!/bin/bash | |
# ツェラーの公式 Zeller | |
# 1991/2/29 | |
# その日付は存在するか | |
# 曜日 | |
days=("日" "月" "火" "水" "木" "金" "土") | |
echo -n "y/m/d: " | |
read ymd | |
# 入力がなかったときは今日の日付を勝手に算出 | |
if [ "$ymd" == "" ]; then | |
ymd=`date +%Y/%-m/%-d` | |
fi | |
# 入力文字列を年・月・日に分割して配列に代入 | |
arr=(`echo "$ymd" | tr -s '/' ' '`) | |
#echo "year: ${arr[0]}" | |
#echo "month: ${arr[1]}" | |
#echo "day: ${arr[2]}" | |
# 中身がわかりやすい変数に入れ直す | |
y=${arr[0]} | |
m=${arr[1]} | |
d=${arr[2]} | |
# 日付のフォーマットをチェック | |
if [ -z `echo $ymd |\ | |
egrep '^([1-9][0-9]{0,3})\/([1-9]|1[0-2])\/([1-9]|[1-2][0-9]|3[0-1])$'` ] | |
then | |
echo 'エラー: 日付の書式が無効です.' | |
exit 1 | |
fi | |
# 日付の有効性をチェック(うるう年考慮) | |
ENDDAY=(31 28 31 30 31 30 31 31 30 31 30 31) | |
LASTDAY=${ENDDAY[$m-1]} | |
if (($m == 2 && $(($y%4)) == 0 && $(($y%100)) != 0 )); then | |
LASTDAY=$(($LASTDAY+1)) | |
elif (($m == 2 && $(($y%400)) == 0)); then | |
LASTDAY=$(($LASTDAY+1)) | |
fi | |
if (($d > $LASTDAY)); then | |
echo 'エラー: その日付は存在しません.' | |
exit 1 | |
fi | |
# ツェラーの公式では(1|2)月を前年の(13|14)月として扱うので、 | |
# (1|2)月の場合には年を-1し、月を+1 | |
if (($m == 1 || $m == 2 )); then | |
y=$(($y-1)) | |
m=$(($m+12)) | |
fi | |
# ツェラーの公式を用いて曜日を算出 | |
zeller=$(($y+$y/4-$y/100+$y/400+(13*$m+8)/5+$d)) | |
zeller=$(($zeller % 7)) | |
# 曜日の表示 | |
echo "$ymd は${days[$zeller]}曜日です." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment