LoginSignup
5

More than 1 year has passed since last update.

paiza POH botchi #ぼっちエンジニア

Last updated at Posted at 2019-01-22

場所順です。

Aランク

有名なプールサイド (ランキング問題)

置ける中で最大のオブジェクトを1個だけ配置することで3656点取れます。

1.rb
#!/usr/bin/ruby
H,W,N=gets.split.map &:to_i
R=H.times.map{[0]*W}
A=N.times.map{|i|
    [i+1]+gets.split.map(&:to_i)
}.select{|e|
    e[1]<=H && e[2]<=W
}.sort_by{|e|
    e[1]*e[2]
}
a=A[-1]
a[1].times{|i|a[2].times{|j|R[i][j]=a[0]}}
puts R.map{|e|e*' '}

Bランク

高層タワー

2.rb
#!/usr/bin/ruby
gets
r=gets.chomp
$<.each{|e|
    e.chomp!
    n=[r.size,e.size].min.downto(0).find{|i|
        i.times.all?{|j|r[-i+j]==e[j]}
    }
    r<<e[n..-1]
}
puts r

砂漠の公園

3.rb
#!/usr/bin/ruby
n=gets.to_i
puts (1..n).map{|i|
    s=gets
    a=[s.count('W'),s.count('D'),s.count('L')]
    [i,a[0]*2+a[1],*a]
}.max_by{|e|e[1]}*' '

隔離された街のゲート

4.rb
#!/usr/bin/ruby
H,W,N=gets.split.map &:to_i
x=y=0
puts N.times.all?{
    dx,dy={'U'=>[0,1],'R'=>[1,0],'D'=>[0,-1],'L'=>[-1,0]}[gets.chomp]
    x+=dx
    y+=dy
    0<=x&&x<W && 0<=y&&y<H
} ? :valid : :invalid

Cランク

荒れ果てたショップ

*は幅指定子です。Cのprintf(/scanf)でも共通。Cはフォーマット文字列を動的に作るのが困難なので使う場面はそれなりにあるかも。

5.rb
#!/usr/bin/ruby
N,A,B=gets.split.map &:to_i
(A..B).map{|e|puts'%0*d'%[N,e]}

機械の総合病院

正規表現で解く場合、/.{3}/ではなく、/(.)\1\1/が正解です。2WAも出してしまったつらいorz

6.rb
#!/usr/bin/ruby
s=gets.chomp
puts s.size>=6 &&
    (s.chars.any?{|c|('a'..'z').include? c} || s.chars.any?{|c|('A'..'Z').include? c}) &&
    s.chars.any?{|c|('0'..'9').include? c} &&
    s.scan(/(.)\1\1/).empty? ? :Valid : :Invalid

学べない学校

数値化して差の剰余を取ることはゴルフでは割とやると思います。

7.rb
gets
puts$<.map{|e|
    a,b=e.split.map{|e|'gcp'.index e}
    [
        [0,0],
        [0,1],
        [1,0],
    ][(a-b)%3]
}.transpose.map &:sum

Dランク

荒れ果てた警察署

(AWK、提出はBash)

8.awk
#!/usr/bin/awk -f
$0=($1+$2)%10a

荒れ果てたオフィス

Bashです

9.sh
#!/bin/sh
sed 1d|grep 3|cut -f1 -d\ 

わかりにくいですが、最後のバックスラッシュの後ろにはスペースが入っています。

アンドロイドの生産工場

Python(3)を選びますよね?

# てかこれ enshura 1問目と全く同じじゃないですか--;;;

10.py
#!/usr/bin/env python3
print(input()[::2])

錆びついた電波塔

11.rb
#!/usr/bin/ruby
gets;p gets.split.map(&:to_i).count{|e|e>5}

お金が引き出せない銀行

12.rb
#!/usr/bin/ruby
n=gets.to_i-gets.to_i;puts n<0?:error:n

そういえば今回、Tupleとしての用途でないArrayを使っていないな?Crystalだったら[]なし縛り可能かもしれぬ(提出できないので、やりませんが)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5