URL | |
---|---|
解答集 | http://qiita.com/cielavenir/items/2fd430a3468a068feef5 |
withVaList()を書いた話 | http://qiita.com/cielavenir/items/2598d47b97a7c9caf970 |
水着チャレンジ(のrobustな解法) | http://qiita.com/cielavenir/items/46f873191b37736d5062 |
readLine()、入ったんですね。知りませんでした。知らなかったのは単なる情弱ですね…
でも、メイド服問題(3d)はvprintf()使わないと解ける気がしません。
全てSwiftです(4bはRubyもあり)。4cは記事を分けました。
paizapoh1a.swift
//usr/bin/env swift $0 $@;exit
var n=Int(readLine()!)!
for ;n>0;--n{print("Ann",terminator:"")}
paizapoh1b.swift
//usr/bin/env swift $0 $@;exit
var lst:[Int: Int]=[:]
var f=false
var r:[Int]=[]
readLine()
readLine()
readLine()!.characters.split{$0==" "}.forEach{lst[Int(String($0))!]=1}
readLine()
readLine()!.characters.split{$0==" "}.forEach{
let n=Int(String($0))!
if lst[n]==nil {r.append(n)}
}
r.sortInPlace()
for var i=0;i<r.count;i++ {
if f {print(" ",terminator:"")}
f=true
print(r[i],terminator:"")
}
print(f ? "" : "None")
paizapoh1c.swift
//usr/bin/env swift $0 $@;exit
var T="cat"
var r=0
var c=0
readLine()!.characters.forEach{
if $0==T[T.startIndex.advancedBy(c)] {
c+=1
if c==T.characters.count {
r+=1
c=0
}
} else {
c=0
if $0==T[T.startIndex.advancedBy(c)] {c=1}
}
}
print(r)
paizapoh1d.swift
//usr/bin/env swift $0 $@;exit
var c=0
var a=0
var t=0
readLine()!.characters.forEach{
if String($0)=="c" {c+=1}
if String($0)=="a" {a+=1}
if String($0)=="t" {t+=1}
}
var ma=[c,a,t].maxElement()!
var mi=[c,a,t].minElement()!
print(mi)
print(ma-c)
print(ma-a)
print(ma-t)
paizapoh2a.swift
//usr/bin/env swift $0 $@;exit
print(Int(readLine()!)!+Int(readLine()!)!)
paizapoh2b.swift
//usr/bin/env swift $0 $@;exit
var n=0,i=0
for ;i<5;++i{if readLine()!=="yes" {n++} else {n--}}
print(n>0 ? "yes" : "no")
paizapoh2c.swift
//usr/bin/env swift $0 $@;exit
var n=Int(readLine()!)!
for ;n>0;--n{print(n)}
print("0!!")
paizapoh2d.swift
//usr/bin/env swift $0 $@;exit
//import CoreFoundation
#if _runtime(_ObjC)
import Darwin
#else
import Glibc
#endif
func getInt()->Int{
var n:Int=0
withUnsafeMutablePointer(&n){withVaList([COpaquePointer($0)]){vscanf("%d",$0)}}
return n
}
var a=getInt(),b=getInt(),c=getInt(),d=getInt()
print(a*d>b*c ? 1 : 2)
paizapoh3a.swift
//usr/bin/env swift $0 $@;exit
var n=Int(readLine()!)!,i=0
for ;i<n;++i{print(readLine()!,terminator:i<n-1 ? "_" : "\n")}
paizapoh3b.swift
//usr/bin/env swift $0 $@;exit
var n=Int(readLine()!)!,r=1
for ;n>1;--n{r*=n}
print(r)
paizapoh3c.swift
//usr/bin/env swift $0 $@;exit
let n=Int(readLine()!)!
let m=Int(readLine()!)!
var i=0,j=0,c=0,a=["R","W"]
for ;i<m;i++ {
print(a[c],terminator:"")
j++
if j==n {j=0;c^=1}
}
paizapoh3d.swift
//usr/bin/env swift $0 $@;exit
//import CoreFoundation
#if _runtime(_ObjC)
import Darwin
#else
import Glibc
#endif
let t=Int(readLine()!)!
var i=0
for i in 0..<t {
var n=(1500-Int(readLine()!)!/3)%1440
withVaList([n/60,n%60]){vprintf("%02d:%02d\n",$0)}
}
paizapoh4a.swift
//usr/bin/env swift $0 $@;exit
func g()->(Int,[[Int]]){x=Int(readLine()!)!;return(x,(0..<x).map{_ in readLine()!.utf8.map{Int($0)}})};var x=0,(n,N)=g(),(m,M)=g()
n-=m-1;z:for i in 0..<n*n{for k in 0..<m*m{if N[i/n+k/m][(i%n+k%m)*2] != M[k/m][k%m*2]{continue z}};print("\(i/n) \(i%n)")}
//n-=m-1;for i in 0..<n*n{let z=(0..<m*m).map{N[i/n+$0/m][i%n+$0%m]==M[$0/m][$0%m]};if(!z.contains{!$0}){print("\(i/n) \(i%n)")}}
paizapoh4b.swift
//usr/bin/env swift $0 $@;exit
//import CoreFoundation
#if _runtime(_ObjC)
import Darwin
#else
import Glibc
#endif
func getInt()->Int{
var n:Int=0
withUnsafeMutablePointer(&n){withVaList([COpaquePointer($0)]){vscanf("%d",$0)}}
return n
}
var x=getInt()
var y=getInt()
var z=getInt()
var n=getInt()
var t=[[0,x],[0,y]]
for i in 0..<n {
var a=getInt()
var b=getInt()
t[a].append(b)
}
var r=z
for i in 0...1 {
t[i].sortInPlace{$0<$1}
var a=i==0 ? x : y
for j in 0...t[i].count-2 {
var a=min(a,t[i][j+1]-t[i][j])
}
r*=a
}
print(r)
paizapoh4b.rb
#!/usr/bin/ruby
x,y,z,n=gets.split.map(&:to_i)
t=[[0,x],[0,y]]
n.times{a,b=gets.split.map(&:to_i);t[a]<< b}
p z*t.map{|e|e.sort.each_cons(2).map{|x,y|y-x}.min}.reduce(:*)