Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

yhpgの「異星の電光掲示板」をSwiftで

More than 3 years have passed since last update.
問題 http://nabetani.sakura.ne.jp/hena/ord15elebubo/
Ruby/C++/Python/C http://qiita.com/cielavenir/items/3d147bdeebcadcb4e3d9
Ruby(Golf,鍋谷さんのアルゴリズム復習) http://qiita.com/cielavenir/items/732a3140efe3db571480
Swift http://qiita.com/cielavenir/items/600e264d39c402b244c1

標準入力の取り方がわかったので。Cの答案を書き換えてみた。
yhpgのSwift答案は初だと思う。

コンパイル方法は http://qiita.com/cielavenir/items/abcf982d2695b357dd5b を参考に。

採点プログラムはv1(C++)とv2(Ruby)両方使える。

tyama_hena15.swift
#!/usr/bin/env xcrun -sdk macosx10.10 swift
//http://qiita.com/Nabetani/items/cba03c96d1ea55f6e861
//http://nabetani.sakura.ne.jp/hena/ord15elebubo/
import Darwin
var v:[UInt]=[0,0] // I cannot specify the array size...
var i=0,j=0
for ;(withUnsafePointer(&v[0]){vscanf("%08x",getVaList([COpaquePointer($0)]))}>0); {
    withUnsafePointer(&v[1]){vscanf("/%08x",getVaList([COpaquePointer($0)]))}
    var a:[[Int]]=[[],[]]
    for i=0;i<2;i++ {
        for j=0;j<32;j++ {
            a[i].append( Int((v[i]>>(31-j))&1) )
        }
        a[i].append(0)
        a[i].append(0)
    }

    for i=0;i<32; {
        if a[0][i] == 0 && a[1][i] == 0 {
            i++
        } else if a[0][i] != 0 && a[1][i] != 0 { //need space; otherwise treated as "a[0][i]!"
            if a[0][i+1] != 0 {
                if a[0][i+2] != 0 {
                    print("N")
                    i+=3
                } else {
                    print("R")
                    i+=2
                }
            } else if a[1][i+1] != 0 {
                if a[1][i+2] != 0 {
                    print("U")
                    i+=3
                }else{
                    print("L")
                    i+=2
                }
            }
        } else if a[0][i] != 0 {
            if a[0][i+2] != 0 {
                print("T")
                i+=3
            } else { //if a[1][i+2] != 0
                print("Z")
                i+=3
            }
        } else {
            if a[0][i+2] != 0 {
                print("S")
                i+=3
            } else {
                print("J")
                i+=2
            }
        }
    }
    println()
    fflush(stdout)
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away