2010-06-04から1日間の記事一覧

SPOJ 42 "Adding Reversed Numbers"

問題:https://www.spoj.pl/problems/ADDREV/普通にexprで計算しようとすると頭が0の場合8進数として扱われるのでscanでとった. proc f {a} { join [lreverse [split $a ""]] "" } for {gets stdin t} {$t>0} {incr t -1} { scan [gets stdin] {%s %s} a b…

SPOJ 24 "Small factorial"

問題:https://www.spoj.pl/problems/FCTRL2/ set a(0) 1 for {set i 1} {$i<=100} {incr i} { set a($i) [expr [set a([expr $i - 1])] * $i] } for {gets stdin t} {$t>0} {incr t -1} { puts [set a([gets stdin])] }

SPOJ 400 "To and Fro"

問題:https://www.spoj.pl/problems/TOANDFRO/ while {[set t [gets stdin]]>0} { gets stdin s set r "" for {set i 1} {$i <= $t} {incr i} { set b 0 for {set j $i} {$j <= [string length $s]} {incr j [expr $b?[expr 2*[expr $t-$i]+1]:[expr 2*$i-1…