├── lib ├── baekjoon │ ├── 1000 │ │ ├── id1237.rb │ │ ├── id1152.rb │ │ ├── id1271.rb │ │ ├── id1085.rb │ │ ├── id1037.rb │ │ ├── id1181.rb │ │ ├── id1436.rb │ │ ├── id1259.rb │ │ ├── id1069.rb │ │ ├── id1003.rb │ │ ├── id1009.rb │ │ ├── id1076.rb │ │ ├── id1011.rb │ │ ├── id1032.rb │ │ ├── id1874.rb │ │ ├── id1978.rb │ │ ├── id1654.rb │ │ ├── id1929.rb │ │ ├── id1002.rb │ │ ├── id1107.rb │ │ ├── id1026.rb │ │ ├── id1016.rb │ │ ├── id1004.rb │ │ ├── id1966.rb │ │ ├── id1019.rb │ │ ├── id1920.rb │ │ ├── id1018.rb │ │ ├── id1786.rb │ │ ├── id1071.rb │ │ └── id1046.rb │ ├── 2000 │ │ ├── id2743.rb │ │ ├── id2558.rb │ │ ├── id2338.rb │ │ ├── id2908.rb │ │ ├── id2609.rb │ │ ├── id2744.rb │ │ ├── id2292.rb │ │ ├── id2475.rb │ │ ├── id2751.rb │ │ ├── id2920.rb │ │ ├── id2754.rb │ │ ├── id2164.rb │ │ ├── id2231.rb │ │ ├── id2775.rb │ │ ├── id2869.rb │ │ ├── id2728.rb │ │ ├── id2805.rb │ │ ├── id2839.rb │ │ ├── id2798.rb │ │ ├── id2718.rb │ │ └── id2108.rb │ ├── 3000 │ │ ├── id3003.rb │ │ └── id3733.rb │ ├── 4000 │ │ ├── id4999.rb │ │ ├── id4101.rb │ │ ├── id4153.rb │ │ └── id4949.rb │ ├── 5000 │ │ ├── id5337.rb │ │ ├── id5522.rb │ │ ├── id5338.rb │ │ └── id5339.rb │ ├── 6000 │ │ └── id6549.rb │ ├── 7000 │ │ ├── id7287.rb │ │ └── id7568.rb │ ├── 8000 │ │ └── id8370.rb │ ├── 9000 │ │ ├── 9012.rb │ │ └── id9663.rb │ ├── 10000 │ │ ├── id11650.rb │ │ ├── id10699.rb │ │ ├── id11382.rb │ │ ├── id10757.rb │ │ ├── id2420.rb │ │ ├── id10872.rb │ │ ├── id11718.rb │ │ ├── id15964.rb │ │ ├── id11050.rb │ │ ├── id17874.rb │ │ ├── id11478.rb │ │ ├── id10773.rb │ │ ├── id11651.rb │ │ ├── id15829.rb │ │ ├── id10250.rb │ │ ├── id10814.rb │ │ ├── id11866.rb │ │ ├── id17087.rb │ │ ├── id10816.rb │ │ ├── id10828.rb │ │ ├── id10845.rb │ │ ├── id10989.rb │ │ ├── id10504.rb │ │ ├── id10866.rb │ │ └── id18111.rb │ ├── 20000 │ │ ├── id24078.rb │ │ └── id24082.rb │ ├── page1 │ │ ├── id18108.rb │ │ ├── id10926.rb │ │ ├── id1000.rb │ │ ├── id1008.rb │ │ ├── id1001.rb │ │ ├── id10998.rb │ │ ├── id10172.rb │ │ ├── id10869.rb │ │ ├── id25083.rb │ │ ├── id2588.rb │ │ └── id10430.rb │ ├── page6 │ │ ├── id11654.rb │ │ ├── id11720.rb │ │ ├── id10809.rb │ │ └── id2675.rb │ ├── page3 │ │ ├── id2741.rb │ │ ├── id2742.rb │ │ ├── id8393.rb │ │ ├── id2438.rb │ │ ├── id10951.rb │ │ ├── id2739.rb │ │ ├── id15552.rb │ │ ├── id10950.rb │ │ ├── id11021.rb │ │ ├── id11022.rb │ │ ├── id2439.rb │ │ ├── id10871.rb │ │ ├── id10952.rb │ │ └── id1110.rb │ ├── page4 │ │ ├── id3052.rb │ │ ├── id10818.rb │ │ ├── id2562.rb │ │ ├── id1546.rb │ │ ├── id8958.rb │ │ ├── id2577.rb │ │ └── id4344.rb │ ├── page2 │ │ ├── id2753.rb │ │ ├── id1330.rb │ │ ├── id14681.rb │ │ ├── id2525.rb │ │ ├── id2884.rb │ │ ├── id9498.rb │ │ └── id2480.rb │ ├── class3 │ │ ├── id9461.rb │ │ ├── id9095.rb │ │ ├── id1620.rb │ │ ├── id1764.rb │ │ ├── id1463.rb │ │ ├── id1676.rb │ │ ├── id1931.rb │ │ ├── id1541.rb │ │ ├── id9375.rb │ │ ├── id5525.rb │ │ ├── id2606.rb │ │ ├── id1992.rb │ │ ├── id1927.rb │ │ ├── id1697.rb │ │ ├── id1260.rb │ │ ├── id1074.rb │ │ ├── id1780.rb │ │ ├── id1389.rb │ │ └── id1012.rb │ ├── class4 │ │ ├── id11053.rb │ │ ├── id15651.rb │ │ ├── id15652.rb │ │ ├── id1629.rb │ │ ├── id1149.rb │ │ ├── id15666.rb │ │ ├── id15654.rb │ │ ├── id15657.rb │ │ ├── id1932.rb │ │ ├── id11660.rb │ │ ├── id9465.rb │ │ ├── id9935.rb │ │ ├── id12865.rb │ │ ├── id9663.rb │ │ ├── id2448.rb │ │ ├── id11725.rb │ │ ├── id15663.rb │ │ ├── id12851.rb │ │ ├── id1991.rb │ │ ├── id11444.rb │ │ └── id1918.rb │ ├── class5 │ │ ├── id2166.rb │ │ ├── id2527.rb │ │ ├── id1202.rb │ │ ├── id17404.rb │ │ ├── id1208.rb │ │ ├── id1197.rb │ │ ├── id1562.rb │ │ ├── id1007.rb │ │ ├── id7579.rb │ │ ├── id1005.rb │ │ ├── id2098.rb │ │ ├── id16566.rb │ │ ├── id2887.rb │ │ └── id2162.rb │ ├── page5 │ │ ├── id1065.rb │ │ ├── id4673.rb │ │ ├── id1644.rb │ │ ├── id7579.rb │ │ ├── id17387.rb │ │ ├── id11049.rb │ │ ├── id12852.rb │ │ └── id2568.rb │ └── retry │ │ ├── id1040.rb │ │ ├── id14436.rb │ │ ├── id1046.rb │ │ └── id1028.rb ├── Start │ └── version.rb └── Start.rb ├── .DS_Store ├── .gitignore ├── .travis.yml ├── test ├── test_helper.rb └── Start_test.rb ├── Gemfile ├── bin ├── setup └── console ├── .idea ├── vcs.xml ├── .gitignore ├── modules.xml └── Start.iml ├── Rakefile ├── LICENSE.txt ├── Start.gemspec ├── README.md └── CODE_OF_CONDUCT.md /lib/baekjoon/10000/id11650.rb: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1237.rb: -------------------------------------------------------------------------------- 1 | puts "문제의 정답" 2 | -------------------------------------------------------------------------------- /lib/baekjoon/20000/id24078.rb: -------------------------------------------------------------------------------- 1 | puts gets.to_i%21 -------------------------------------------------------------------------------- /lib/baekjoon/20000/id24082.rb: -------------------------------------------------------------------------------- 1 | puts gets.to_i**3 -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2743.rb: -------------------------------------------------------------------------------- 1 | p gets.chomp.length 2 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id10699.rb: -------------------------------------------------------------------------------- 1 | puts Time.now.to_s.split[0] -------------------------------------------------------------------------------- /lib/baekjoon/7000/id7287.rb: -------------------------------------------------------------------------------- 1 | puts 160 2 | puts "persestitan" -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1152.rb: -------------------------------------------------------------------------------- 1 | p gets.chomp.split(" ").length 2 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id11382.rb: -------------------------------------------------------------------------------- 1 | p gets.chomp.split.map(&:to_i).sum -------------------------------------------------------------------------------- /lib/baekjoon/10000/id10757.rb: -------------------------------------------------------------------------------- 1 | p gets.chomp.split.map(&:to_i).sum 2 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2558.rb: -------------------------------------------------------------------------------- 1 | a=gets.to_i 2 | b=gets.to_i 3 | p a+b -------------------------------------------------------------------------------- /lib/baekjoon/page1/id18108.rb: -------------------------------------------------------------------------------- 1 | values = gets.to_i 2 | puts values-543 -------------------------------------------------------------------------------- /lib/Start/version.rb: -------------------------------------------------------------------------------- 1 | module Start 2 | VERSION = "0.1.0" 3 | end 4 | -------------------------------------------------------------------------------- /lib/baekjoon/page1/id10926.rb: -------------------------------------------------------------------------------- 1 | values = gets.chomp 2 | puts values + "??!" -------------------------------------------------------------------------------- /lib/baekjoon/page6/id11654.rb: -------------------------------------------------------------------------------- 1 | value = gets.chomp 2 | pp value.ord 3 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PersesTitan/RubyBaekjoon/HEAD/.DS_Store -------------------------------------------------------------------------------- /lib/Start.rb: -------------------------------------------------------------------------------- 1 | a, b, c, d = gets.chomp.split.map(&:to_i) 2 | puts a * b + c * d -------------------------------------------------------------------------------- /lib/baekjoon/10000/id2420.rb: -------------------------------------------------------------------------------- 1 | a, b = gets.chomp.split.map(&:to_i) 2 | p (a-b).abs -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2338.rb: -------------------------------------------------------------------------------- 1 | a = gets.to_i 2 | b = gets.to_i 3 | p a+b 4 | p a-b 5 | p a*b 6 | -------------------------------------------------------------------------------- /lib/baekjoon/8000/id8370.rb: -------------------------------------------------------------------------------- 1 | a, b, c, d = gets.chomp.split.map(&:to_i) 2 | puts a * b + c * d 3 | -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1271.rb: -------------------------------------------------------------------------------- 1 | n = gets.chomp.split.map(&:to_i) 2 | puts n[0]/n[1] 3 | puts n[0]%n[1] 4 | -------------------------------------------------------------------------------- /lib/baekjoon/5000/id5337.rb: -------------------------------------------------------------------------------- 1 | print ". . . 2 | | | _ | _. _ ._ _ _ 3 | |/\\|(/.|(_.(_)[ | )(/." 4 | -------------------------------------------------------------------------------- /lib/baekjoon/page3/id2741.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | 3 | (1..count).each do |i| 4 | puts i 5 | end 6 | -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1085.rb: -------------------------------------------------------------------------------- 1 | a, b, c, d = gets.chomp.split(" ").map(&:to_i) 2 | p [a, b, c-a, d-b].min 3 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2908.rb: -------------------------------------------------------------------------------- 1 | a, b = gets.chomp.split(" ") 2 | puts [a.reverse!.to_i, b.reverse!.to_i].max 3 | -------------------------------------------------------------------------------- /lib/baekjoon/4000/id4999.rb: -------------------------------------------------------------------------------- 1 | a = gets.chomp.length 2 | b = gets.chomp.length 3 | puts a < b ? "no" : "go" 4 | -------------------------------------------------------------------------------- /lib/baekjoon/5000/id5522.rb: -------------------------------------------------------------------------------- 1 | total = 0 2 | (1..5).each do 3 | total += gets.to_i 4 | end 5 | p total 6 | -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1037.rb: -------------------------------------------------------------------------------- 1 | gets 2 | list = gets.chomp.split.map(&:to_i).to_a 3 | puts list.max * list.min 4 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2609.rb: -------------------------------------------------------------------------------- 1 | a, b = gets.chomp.split(" ").map{|v| v.to_i} 2 | puts a.gcd(b) 3 | puts a.lcm(b) 4 | -------------------------------------------------------------------------------- /lib/baekjoon/page1/id1000.rb: -------------------------------------------------------------------------------- 1 | values = gets.chomp.split 2 | a = values[0].to_i 3 | b = values[1].to_i 4 | puts a+b -------------------------------------------------------------------------------- /lib/baekjoon/page1/id1008.rb: -------------------------------------------------------------------------------- 1 | values = gets.chomp.split 2 | a = values[0].to_f 3 | b = values[1].to_f 4 | puts a/b -------------------------------------------------------------------------------- /lib/baekjoon/page3/id2742.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | 3 | (0..count-1).each do |i| 4 | puts count-i 5 | end 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | -------------------------------------------------------------------------------- /lib/baekjoon/page1/id1001.rb: -------------------------------------------------------------------------------- 1 | values = gets.chomp.split 2 | a = values[0].to_i 3 | b = values[1].to_i 4 | puts a-b 5 | -------------------------------------------------------------------------------- /lib/baekjoon/page1/id10998.rb: -------------------------------------------------------------------------------- 1 | values = gets.chomp.split 2 | a = values[0].to_i 3 | b = values[1].to_i 4 | puts a*b 5 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id10872.rb: -------------------------------------------------------------------------------- 1 | i = gets.to_i 2 | total = 1 3 | (1..i).each do |j| 4 | total *=j 5 | end 6 | 7 | puts total -------------------------------------------------------------------------------- /lib/baekjoon/10000/id11718.rb: -------------------------------------------------------------------------------- 1 | while true 2 | begin 3 | puts gets.chomp 4 | rescue 5 | break 6 | end 7 | end -------------------------------------------------------------------------------- /lib/baekjoon/10000/id15964.rb: -------------------------------------------------------------------------------- 1 | test = gets.chomp.split(" ") 2 | a = test[0].to_i 3 | b = test[1].to_i 4 | p (a+b)*(a-b) 5 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id11050.rb: -------------------------------------------------------------------------------- 1 | # 파이썬 2 | # import math 3 | # a, b = map(int, input().split()) 4 | # print(math.comb(a, b)) 5 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2744.rb: -------------------------------------------------------------------------------- 1 | gets.chomp.split("").each do |n| 2 | print /[a-z]/.match(n) ? n.upcase : n.downcase 3 | end 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: ruby 3 | cache: bundler 4 | rvm: 5 | - 2.7.2 6 | before_install: gem install bundler -v 2.1.4 7 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2292.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | count = 1 3 | c = 1 4 | while n > count 5 | count += 6*c 6 | c += 1 7 | end 8 | p c 9 | -------------------------------------------------------------------------------- /lib/baekjoon/5000/id5338.rb: -------------------------------------------------------------------------------- 1 | puts " _.-;;-._ 2 | '-..-'| || | 3 | '-..-'|_.-;;-._| 4 | '-..-'| || | 5 | '-..-'|_.-''-._|" 6 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path("../lib", __dir__) 2 | require "Start" 3 | 4 | require "minitest/autorun" 5 | -------------------------------------------------------------------------------- /lib/baekjoon/page3/id8393.rb: -------------------------------------------------------------------------------- 1 | number = gets.to_i 2 | 3 | total = 0 4 | (1..number).each do |i| 5 | total += i 6 | end 7 | 8 | puts total 9 | -------------------------------------------------------------------------------- /lib/baekjoon/page3/id2438.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | 3 | (1..count).each do |i| 4 | (1..i).each do 5 | print "*" 6 | end 7 | puts 8 | end 9 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2475.rb: -------------------------------------------------------------------------------- 1 | nums = gets.chomp.split(" ") 2 | total = nums.pop.to_i**2 3 | nums.each { |n| 4 | total += n.to_i**2 5 | } 6 | puts total%10 7 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id17874.rb: -------------------------------------------------------------------------------- 1 | line = gets.chomp.split(" ") 2 | a = line[0].to_i 3 | b = line[1].to_i 4 | c = line[2].to_i 5 | p ([c, a-c].max * [b, a-b].max)*4 6 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2751.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | array = [] 3 | (0..n-1).each do 4 | array< 12.0" 7 | gem "minitest", "~> 5.0" 8 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /lib/baekjoon/page1/id10869.rb: -------------------------------------------------------------------------------- 1 | values = gets.chomp.split 2 | a = values[0].to_i 3 | b = values[1].to_i 4 | puts a+b 5 | puts a-b 6 | puts a*b 7 | puts a/b 8 | puts a%b 9 | -------------------------------------------------------------------------------- /lib/baekjoon/4000/id4101.rb: -------------------------------------------------------------------------------- 1 | while true 2 | a, b = gets.chomp.split.map(&:to_i) 3 | if a == 0 and b == 0 4 | break 5 | end 6 | puts a > b ? "Yes" : "No" 7 | end 8 | -------------------------------------------------------------------------------- /lib/baekjoon/page3/id10951.rb: -------------------------------------------------------------------------------- 1 | while true 2 | begin 3 | value = gets.chomp.split(" ") 4 | puts value[0].to_i + value[1].to_i 5 | rescue 6 | break; 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/baekjoon/page6/id11720.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | value = gets.chomp 3 | total = 0 4 | 5 | (0..count-1).each do|i| 6 | total += value[i].to_i 7 | end 8 | 9 | pp total 10 | -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1436.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | s = 666 3 | c = 0 4 | 5 | until c == n 6 | if s.to_s.include? '666' 7 | c+=1 8 | end 9 | s+=1 10 | end 11 | puts s-1 12 | 13 | -------------------------------------------------------------------------------- /lib/baekjoon/page1/id25083.rb: -------------------------------------------------------------------------------- 1 | puts " ,r'\"7\n" + 2 | "r`-_ ,' ,/\n" + 3 | " \\. \". L_r'\n" + 4 | " `~\\/\n" + 5 | " |\n" + 6 | " |" -------------------------------------------------------------------------------- /lib/baekjoon/page1/id2588.rb: -------------------------------------------------------------------------------- 1 | v1 = gets.to_i 2 | v2 = gets.chomp 3 | v = v2.split("") 4 | i = v.length - 1 5 | (0..i).each do|c| 6 | puts v1 * v[i-c].to_i 7 | end 8 | puts v1 * v2.to_i 9 | -------------------------------------------------------------------------------- /lib/baekjoon/page2/id2753.rb: -------------------------------------------------------------------------------- 1 | module Start 2 | year = gets.chomp.to_i 3 | if (year%4 == 0 and year%100 != 0) or year%400 == 0 4 | puts "1" 5 | else 6 | puts "0" 7 | end 8 | end -------------------------------------------------------------------------------- /lib/baekjoon/page3/id2739.rb: -------------------------------------------------------------------------------- 1 | dan = gets.to_i 2 | 3 | (1..9).each { |i| 4 | puts "#{dan} * #{i} = #{i * dan}" 5 | } 6 | 7 | # for i in 1..9 8 | # puts "#{dan} * #{i} = #{i * dan}" 9 | # end -------------------------------------------------------------------------------- /lib/baekjoon/5000/id5339.rb: -------------------------------------------------------------------------------- 1 | puts " /~\\ 2 | ( oo| 3 | _\\=/_ 4 | / _ \\ 5 | //|/.\\|\\\\ 6 | || \\ / || 7 | ============ 8 | | | 9 | | | 10 | | |" -------------------------------------------------------------------------------- /lib/baekjoon/page3/id15552.rb: -------------------------------------------------------------------------------- 1 | number = gets.to_i 2 | 3 | (1..number).each do |i| 4 | text = gets.chomp 5 | a = text.split(" ")[0].to_i 6 | b = text.split(" ")[1].to_i 7 | puts a + b 8 | end 9 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2920.rb: -------------------------------------------------------------------------------- 1 | music = gets.chomp 2 | if "1 2 3 4 5 6 7 8" == music 3 | puts "ascending" 4 | elsif "8 7 6 5 4 3 2 1" == music 5 | puts "descending" 6 | else 7 | puts "mixed" 8 | end 9 | -------------------------------------------------------------------------------- /lib/baekjoon/class3/id9461.rb: -------------------------------------------------------------------------------- 1 | t = gets.to_i 2 | (0..t-1).each do 3 | n = gets.to_i 4 | d = [0, 1, 1, 1] 5 | (4..n).each do |i| 6 | d<<(d[i-2]+d[i-3]) 7 | end 8 | puts d[n] 9 | end 10 | -------------------------------------------------------------------------------- /lib/baekjoon/page3/id10950.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | 3 | (1..count).each do 4 | value = gets.chomp 5 | a = value.split(" ")[0].to_i 6 | b = value.split(" ")[1].to_i 7 | puts "#{a + b}" 8 | end 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lib/baekjoon/page1/id10430.rb: -------------------------------------------------------------------------------- 1 | values = gets.chomp.split 2 | a = values[0].to_i 3 | b = values[1].to_i 4 | c = values[2].to_i 5 | puts (a+b)%c 6 | puts ((a%c)+(b%c))%c 7 | puts (a*b)%c 8 | puts ((a%c)*(b%c))%c 9 | -------------------------------------------------------------------------------- /lib/baekjoon/page2/id1330.rb: -------------------------------------------------------------------------------- 1 | values = gets.chomp.split 2 | a = values[0].to_i 3 | b = values[1].to_i 4 | 5 | if a > b 6 | puts ">" 7 | elsif a < b 8 | puts "<" 9 | else 10 | puts "==" 11 | end 12 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2754.rb: -------------------------------------------------------------------------------- 1 | a = {"A+"=> 4.3, "A0"=> 4.0, "A-"=> 3.7, "B+"=> 3.3, "B0"=> 3.0, "B-"=> 2.7, "C+"=> 2.3, "C0"=> 2.0, "C-"=> 1.7, "D+"=> 1.3, "D0"=> 1.0, "D-"=> 0.7, "F"=> 0.0} 2 | print a[gets.chomp] 3 | -------------------------------------------------------------------------------- /lib/baekjoon/class3/id9095.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | (0..n-1).each do 3 | k = gets.to_i 4 | d = [0, 1, 2, 4] 5 | (4..k+1).each do |i| 6 | d << (d[i-1]+d[i-2]+d[i-3]) 7 | end 8 | puts d[k] 9 | end 10 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id11478.rb: -------------------------------------------------------------------------------- 1 | require 'set' 2 | line = gets.chomp 3 | 4 | set = Set.new 5 | (0..line.size).each do |i| 6 | (i..line.size).each do |j| 7 | set<=i 10 | p (i-(s/2).to_i)*2 11 | break 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/baekjoon/page3/id11021.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | 3 | (1..count).each do|i| 4 | text = gets.chomp 5 | a = text.split(" ")[0].to_i 6 | b = text.split(" ")[1].to_i 7 | 8 | puts "Case ##{i}: #{a+b}" 9 | end 10 | -------------------------------------------------------------------------------- /lib/baekjoon/page3/id11022.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | 3 | (1..count).each do |i| 4 | text = gets.chomp 5 | a = text.split(" ")[0].to_i 6 | b = text.split(" ")[1].to_i 7 | puts "Case ##{i}: #{a} + #{b} = #{a+b}" 8 | end 9 | -------------------------------------------------------------------------------- /lib/baekjoon/page3/id2439.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | 3 | (1..count).each do |i| 4 | (1..count-i).each { 5 | print " " 6 | } 7 | 8 | (1..i).each { 9 | print "*" 10 | } 11 | 12 | print "\n" 13 | end 14 | -------------------------------------------------------------------------------- /lib/baekjoon/page4/id2562.rb: -------------------------------------------------------------------------------- 1 | arr = Array.new 2 | 3 | (0..8).each do |i| 4 | arr << gets.to_i 5 | end 6 | 7 | int = arr.max 8 | (1..9).each do |i| 9 | if int == arr[i-1] 10 | puts int 11 | puts i 12 | end 13 | end -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1259.rb: -------------------------------------------------------------------------------- 1 | while true 2 | text = gets.chomp 3 | if text=="0" 4 | break 5 | else 6 | if text == text.reverse 7 | puts "yes" 8 | else 9 | puts "no" 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/baekjoon/page4/id1546.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | subject = Array.new 3 | values = gets.chomp.split(" ") 4 | 5 | values.each { |value| 6 | subject << value.to_i 7 | } 8 | 9 | puts subject.reduce(:+).to_f/ count / subject.max * 100 10 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rake/testtask" 3 | 4 | Rake::TestTask.new(:test) do |t| 5 | t.libs << "test" 6 | t.libs << "lib" 7 | t.test_files = FileList["test/**/*_test.rb"] 8 | end 9 | 10 | task :default => :test 11 | -------------------------------------------------------------------------------- /lib/baekjoon/page3/id10871.rb: -------------------------------------------------------------------------------- 1 | count = gets.chomp 2 | value = gets.chomp.split(" ") 3 | 4 | number = count.split(" ") 5 | 6 | (0..number[0].to_i-1).each do|i| 7 | if value[i].to_i < number[1].to_i 8 | print "#{value[i].to_i} " 9 | end 10 | end -------------------------------------------------------------------------------- /lib/baekjoon/page3/id10952.rb: -------------------------------------------------------------------------------- 1 | while true 2 | value = gets.chomp 3 | # if value.equal?"0 0" 백준에서 런타임 에러 발생함 4 | 5 | if value == "0 0" 6 | break; 7 | end 8 | a = value.split(" ")[0].to_i 9 | b = value.split(" ")[1].to_i 10 | puts a+b 11 | end -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1069.rb: -------------------------------------------------------------------------------- 1 | a, b, c, d = gets.chomp.split(" ").map { |v| v.to_i} 2 | l = Math.sqrt(a**2+b**2) 3 | if l>=c 4 | j = (l/c).to_i 5 | puts sprintf('%.10f', [l, j*d+l-(j*c), (j+1)*d].min) 6 | else 7 | puts sprintf('%.10f', [l, d+c-l, 2*d].min) 8 | end 9 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2231.rb: -------------------------------------------------------------------------------- 1 | check = true 2 | v = gets.to_i 3 | (0..v-1).each do |i| 4 | t = i.to_s.split("").map { |j| j.to_i}.sum 5 | if (i+t) == v 6 | check = false 7 | p i 8 | break 9 | end 10 | end 11 | 12 | if check 13 | p 0 14 | end 15 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2775.rb: -------------------------------------------------------------------------------- 1 | t = gets.to_i 2 | (0..t-1).each do 3 | f = gets.to_i 4 | n = gets.to_i 5 | fz = Array(1..n) 6 | (0..f-1).each do 7 | (1..n-1).each do |j| 8 | fz[j] += fz[j-1] 9 | end 10 | end 11 | puts(fz[-1]) 12 | end 13 | -------------------------------------------------------------------------------- /lib/baekjoon/class3/id1620.rb: -------------------------------------------------------------------------------- 1 | n, m = gets.split.map(&:to_i) 2 | dict = Hash.new 3 | (1..n).each do |i| 4 | p = gets.chomp 5 | dict[i.to_s] = p 6 | dict[p] = i 7 | end 8 | 9 | (1..m).each do 10 | s = gets.chomp 11 | puts dict[s] 12 | end 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/Start_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class StartTest < Minitest::Test 4 | def test_that_it_has_a_version_number 5 | refute_nil ::Start::VERSION 6 | end 7 | 8 | def test_it_does_something_useful 9 | assert false 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id10250.rb: -------------------------------------------------------------------------------- 1 | t = gets.to_i 2 | (0..t-1).each do |i| 3 | a, b, c = gets.chomp.split(" ").map{|s| s.to_i} 4 | num = (c/a).to_i + 1 5 | f = c % a 6 | if c%a == 0 7 | num = (c/a).to_i 8 | f = a 9 | end 10 | puts f*100+num 11 | end 12 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2869.rb: -------------------------------------------------------------------------------- 1 | # 시간 초과 -> pypy3 2 | # a, b, c = map(int, input().split()) 3 | # k = (c-b)/(a-b) 4 | # print(int(k) if k==int(k) else int(k)+1) 5 | 6 | a, b, c = gets.chomp.split(' ').map{|s| s.to_i} 7 | k = (c-b)/(a-b) 8 | puts k==k.to_i ? k.to_i : k.to_i+1 9 | -------------------------------------------------------------------------------- /lib/baekjoon/class4/id11053.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | a = gets.chomp.split.map(&:to_i) 3 | dp = [1] * n 4 | (1..n-1).each do |i| 5 | (0..i-1).each do |j| 6 | if a[i] > a[j] 7 | dp[i] = [dp[i], dp[j]+1].max 8 | end 9 | end 10 | end 11 | 12 | puts dp.max 13 | -------------------------------------------------------------------------------- /lib/baekjoon/4000/id4153.rb: -------------------------------------------------------------------------------- 1 | while true 2 | a = gets.chomp.split(" ").map{|s| s.to_i} 3 | if a.sum == 0 4 | break 5 | end 6 | mn = a.max 7 | a.delete(mn) 8 | if a[0]**2 + a[1]**2 == mn**2 9 | puts 'right' 10 | else 11 | puts 'wrong' 12 | end 13 | end -------------------------------------------------------------------------------- /lib/baekjoon/class3/id1764.rb: -------------------------------------------------------------------------------- 1 | @n, @m = gets.split.map(&:to_i) 2 | @s = [] 3 | def dfs() 4 | if @s.length == @m 5 | puts @s.map(&:to_s).join(" ") 6 | return 7 | end 8 | (1..@n).each do |i| 9 | @s< 1 7 | (0..m-1).each do 8 | c1 << c2[-1] 9 | c2 << (c1[-2] + c2[-1]) 10 | end 11 | end 12 | puts "#{c1[m]} #{c2[m]}" 13 | end 14 | -------------------------------------------------------------------------------- /lib/baekjoon/class3/id1463.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | d = [0] * (n+1) 3 | 4 | (2..n).each do |i| 5 | d[i] = d[i-1] + 1 6 | if i%3 == 0 7 | d[i] = [d[i], d[(i/3).to_i]+1].min 8 | end 9 | if i%2 == 0 10 | d[i] = [d[i], d[(i/2).to_i]+1].min 11 | end 12 | end 13 | puts d[n] -------------------------------------------------------------------------------- /lib/baekjoon/10000/id10814.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | array = [] 3 | (1..count).each do 4 | text = gets.chomp.split(" ") 5 | a = text[0].to_i 6 | b = text[1] 7 | array<<[a, b] 8 | end 9 | 10 | array.sort_by!{|v| v[0]}.each do |i| 11 | puts "#{i[0]} #{i[1]}" 12 | end 13 | 14 | -------------------------------------------------------------------------------- /lib/baekjoon/class3/id1676.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | ans = 0 3 | num = 1 4 | (2..n).each do |i| 5 | num *= i 6 | end 7 | 8 | ns = num.to_s 9 | (0..ns.length-1).reverse_each { |i| 10 | if ns[i.to_i] == '0' 11 | ans += 1 12 | else 13 | break 14 | end 15 | } 16 | puts ans 17 | -------------------------------------------------------------------------------- /lib/baekjoon/class4/id15652.rb: -------------------------------------------------------------------------------- 1 | @n, @m = gets.split.map(&:to_i) 2 | @s = [] 3 | def dfs(start) 4 | if @s.length == @m 5 | puts @s.map(&:to_s).join(" ") 6 | return 7 | end 8 | (start..@n).each do |i| 9 | @s< 0 ,"brown" => 1 ,"red" => 2 ,"orange" => 3 ,"yellow" => 4 ,"green" => 5 ,"blue" => 6 ,"violet" => 7 ,"grey" => 8 ,"white" => 9] 2 | a = color[gets.chomp] 3 | b = color[gets.chomp] 4 | c = color[gets.chomp] 5 | puts (a.to_s + b.to_s).to_i * (10 ** c) -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /lib/baekjoon/page3/id1110.rb: -------------------------------------------------------------------------------- 1 | number = gets.to_i 2 | count = 0 3 | int = number 4 | 5 | while true 6 | n1 = int%10 7 | n10 = int/10 8 | sum = (n1 + n10)%10 9 | 10 | int = (n1 * 10) + sum 11 | 12 | count+=1 13 | if int == number 14 | break; 15 | end 16 | end 17 | puts count 18 | -------------------------------------------------------------------------------- /lib/baekjoon/page2/id2525.rb: -------------------------------------------------------------------------------- 1 | text = gets.chomp 2 | use_time = gets.to_i 3 | a = text.split(" ")[0].to_i 4 | b = text.split(" ")[1].to_i 5 | day = 60 * 24 6 | 7 | b += a * 60 8 | b += use_time 9 | 10 | if b >= day 11 | b -= day 12 | end 13 | 14 | hour = b/60 15 | min = b%60 16 | printf "%d %d", hour, min 17 | -------------------------------------------------------------------------------- /lib/baekjoon/class4/id1629.rb: -------------------------------------------------------------------------------- 1 | a, b, @c = gets.chomp.split.map(&:to_i) 2 | def mul(a, n) 3 | if n == 1 4 | return a%@c 5 | else 6 | tmp = mul(a, (n/2).to_i) 7 | if n%2 == 0 8 | return (tmp*tmp)%@c 9 | else 10 | return (tmp*tmp*a)%@c 11 | end 12 | end 13 | end 14 | puts mul(a, b) 15 | -------------------------------------------------------------------------------- /lib/baekjoon/class5/id2166.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | x, y = [], [] 3 | ans = 0 4 | (0...n).each do 5 | a, b = gets.chomp.split.map(&:to_i) 6 | x << a 7 | y << b 8 | end 9 | x, y = x + [x[0]], y + [y[0]] 10 | 11 | (0...n).each do |i| 12 | ans += (x[i]*y[i+1])-(x[i+1]*y[i]) 13 | end 14 | puts (ans.abs.to_f/2).round(1) -------------------------------------------------------------------------------- /lib/baekjoon/page2/id2884.rb: -------------------------------------------------------------------------------- 1 | text = gets.chomp 2 | h = text.split(" ")[0].to_i 3 | m = text.split(" ")[1].to_i 4 | 5 | m += (h*60) 6 | m -= 45 7 | if m<0 8 | m = (60 * 24) + m 9 | hour = m/60 10 | min = m%60 11 | puts "#{hour} #{min}" 12 | else 13 | hour = m/60 14 | min = m%60 15 | puts "#{hour} #{min}" 16 | end 17 | -------------------------------------------------------------------------------- /lib/baekjoon/page4/id8958.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | 3 | def point(texts) 4 | total = 0 5 | text = texts.split("X") 6 | text.each { |t| 7 | (1..t.size).each do|i| 8 | total += i 9 | end 10 | } 11 | total 12 | end 13 | 14 | (1..count).each do 15 | value = gets.chomp 16 | puts point(value) 17 | end 18 | -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1011.rb: -------------------------------------------------------------------------------- 1 | v = gets.to_i 2 | (0..v-1).each do 3 | x, y = gets.chomp.split(" ").map{|s| s.to_i} 4 | d = y - x 5 | n = 0 6 | while true 7 | if d<= n*(n+1) 8 | break 9 | end 10 | n+=1 11 | end 12 | if d <= n**2 13 | puts n*2-1 14 | else 15 | puts n*2 16 | end 17 | end 18 | 19 | -------------------------------------------------------------------------------- /lib/baekjoon/page5/id1065.rb: -------------------------------------------------------------------------------- 1 | int = gets.to_i 2 | 3 | if int < 100 4 | puts int 5 | else 6 | count = 99 7 | (100..int).each do|i| 8 | n1 = i % 10 9 | n10 = (i / 10) % 10 10 | n100 = i / 100 11 | 12 | if (n100 - n10) == (n10 - n1) 13 | count += 1 14 | end 15 | end 16 | 17 | puts count 18 | end 19 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id11866.rb: -------------------------------------------------------------------------------- 1 | n, k = gets.split.map(&:to_i) 2 | q, a = [], [] 3 | (1..n).each do |i| 4 | q< 0 8 | (0..k-2).each do 9 | q<") 18 | -------------------------------------------------------------------------------- /lib/baekjoon/class3/id1931.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | meet = [] 3 | (0..n-1).each do 4 | st, en = gets.split.map(&:to_i) 5 | meet << [st, en] 6 | end 7 | meet.sort_by!{|e| e[0]} 8 | meet.sort_by!{|e| e[1]} 9 | now, cnt = 0, 0 10 | meet.each { |st, en| 11 | if now <= st 12 | now = en 13 | cnt += 1 14 | end 15 | } 16 | 17 | puts cnt 18 | -------------------------------------------------------------------------------- /lib/baekjoon/page4/id2577.rb: -------------------------------------------------------------------------------- 1 | value1 = gets.to_i 2 | value2 = gets.to_i 3 | value3 = gets.to_i 4 | 5 | total = value1 * value2 * value3 6 | arr = Array.new 7 | 8 | (0..9).each do 9 | arr << 0 10 | end 11 | 12 | while total > 0 13 | arr[total%10] += 1 14 | total /= 10 15 | end 16 | 17 | (0..9).each do |i| 18 | puts arr[i] 19 | end 20 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2728.rb: -------------------------------------------------------------------------------- 1 | b = [] 2 | n, m = gets.chomp.split.map(&:to_i) 3 | (0...n).each do 4 | b << gets.chomp.split.map(&:to_i) 5 | end 6 | (0...n).each do |i| 7 | temp = gets.chomp.split.map(&:to_i).to_a 8 | (0...m).each do |j| 9 | b[i][j] += temp[j] 10 | end 11 | end 12 | (0...n).each do |i| 13 | puts b[i].join(" ") 14 | end 15 | -------------------------------------------------------------------------------- /lib/baekjoon/class3/id1541.rb: -------------------------------------------------------------------------------- 1 | num = gets.split("-") 2 | ans = [] 3 | a = 0 4 | num.each { |i| 5 | tmp = 0 6 | i.split("+").each { |j| 7 | tmp += j.to_i 8 | } 9 | ans<= 90 and a <= 100 이렇게도 가능함 4 | if a >= 90 && a <= 100 5 | puts 'A' 6 | elsif a >= 80 and a <= 89 7 | puts 'B' 8 | elsif a >= 70 and a <= 79 9 | puts "C" 10 | elsif a >= 60 and a <= 69 11 | puts "D" 12 | else 13 | puts "F" 14 | end 15 | end -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1032.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | array = [] 3 | (1..count).each do 4 | array<=n 15 | s = m + 1 16 | else 17 | e = m - 1 18 | end 19 | end 20 | p e -------------------------------------------------------------------------------- /lib/baekjoon/class3/id5525.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | m = gets.to_i 3 | letter = gets.chomp 4 | left, right = 0, 0 5 | cnt = 0 6 | while right mi 11 | c += o-mi 12 | end 13 | } 14 | if c >= m 15 | s = mi+1 16 | else 17 | e = mi-1 18 | end 19 | end 20 | p e 21 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2839.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | 3 | if n % 5 == 0 4 | puts (n/5).to_i 5 | else 6 | p = 0 7 | while n > 0 8 | n -= 3 9 | p += 1 10 | if n%5 == 0 11 | p += (n/5).to_i 12 | puts p 13 | break 14 | elsif n == 1 || n == 2 15 | puts -1 16 | break 17 | elsif n == 0 18 | puts p 19 | break 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "Start" 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require "irb" 14 | IRB.start(__FILE__) 15 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id10816.rb: -------------------------------------------------------------------------------- 1 | gets 2 | a_list = gets.chomp.split(" ").map { |v| v.to_i}.sort 3 | gets 4 | b_list = gets.chomp.split(" ").map { |v| v.to_i} 5 | 6 | hash = Hash.new 7 | a_list.each { |i| 8 | if hash.include? i 9 | hash[i] += 1 10 | else 11 | hash[i] = 1 12 | end 13 | } 14 | 15 | b_list.each { |i| 16 | if hash.include? i 17 | print("#{hash[i]} ") 18 | else 19 | print("0 ") 20 | end 21 | } -------------------------------------------------------------------------------- /lib/baekjoon/class4/id15666.rb: -------------------------------------------------------------------------------- 1 | @n, @m = gets.split.map(&:to_i) 2 | @nums = gets.split.map(&:to_i).uniq.sort.to_a 3 | @arr = [] 4 | 5 | def sol(d) 6 | if d == @m 7 | puts @arr.map(&:to_s).join(" ") 8 | return 9 | end 10 | (0..@nums.length-1).each do |i| 11 | if d == 0 || @arr[-1] <= @nums[i] 12 | @arr<<@nums[i] 13 | sol(d+1) 14 | @arr.pop 15 | end 16 | end 17 | end 18 | 19 | sol(0) 20 | -------------------------------------------------------------------------------- /lib/baekjoon/2000/id2798.rb: -------------------------------------------------------------------------------- 1 | n, m = gets.chomp.split(' ').map{|s| s.to_i} 2 | array = gets.chomp.split(' ').map{|s| s.to_i} 3 | r = 0 4 | (0..n-1).each do |i| 5 | (i+1..n-1).each do |j| 6 | (j+1..n-1).each do |k| 7 | t = array[i] + array[j] + array[k] 8 | if t > m 9 | next 10 | else 11 | if r < t 12 | r = t 13 | end 14 | end 15 | end 16 | end 17 | end 18 | p r 19 | -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1016.rb: -------------------------------------------------------------------------------- 1 | a, b = gets.chomp.split(" ").map{|s| s.to_i} 2 | value = b - a + 1 3 | check = [] 4 | (1..value).each do 5 | check< pr) or (d1 > pr and d2 k 31 | def nk(n) 32 | 33 | end 34 | -------------------------------------------------------------------------------- /lib/baekjoon/9000/9012.rb: -------------------------------------------------------------------------------- 1 | def check(line) 2 | if line[0] == ')' && line[-1] == '(' 3 | return false 4 | end 5 | array = [] 6 | line.split("").each do |i| 7 | if i == "(" 8 | array << "(" 9 | end 10 | if i == ")" 11 | if array.length != 0 12 | array.pop 13 | else 14 | return false 15 | end 16 | end 17 | end 18 | array.length == 0 19 | end 20 | 21 | count = gets.to_i 22 | (1..count).each do 23 | puts check(gets.chomp) ? "YES" : "NO" 24 | end 25 | -------------------------------------------------------------------------------- /lib/baekjoon/class4/id2448.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | @ans = [] 3 | (0..n-1).each do 4 | @ans<<[' '] * 2 * n 5 | end 6 | 7 | def start(x, y, n) 8 | if n == 3 9 | @ans[x][y] = '*' 10 | @ans[x+1][y-1] = @ans[x+1][y+1] = "*" 11 | (-2..2).each do |i| 12 | @ans[x+2][y+i] = "*" 13 | end 14 | else 15 | nn = (n/2).to_i 16 | start(x, y, nn) 17 | start(x+nn, y-nn, nn) 18 | start(x+nn, y+nn, nn) 19 | end 20 | end 21 | start(0, n-1, n) 22 | @ans.each { |row| 23 | puts row.join("") 24 | } 25 | -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1966.rb: -------------------------------------------------------------------------------- 1 | t = gets.to_i 2 | 3 | (0..t-1).each do 4 | m = gets.chomp.split(" ").map { |v| v.to_i}[1] 5 | q = gets.chomp.split(" ").map { |v| v.to_i}.reverse 6 | count = 0 7 | while q 8 | b = q.max 9 | f = q.pop 10 | m-=1 11 | if b == f 12 | count+=1 13 | if m<0 14 | puts count 15 | break 16 | end 17 | else 18 | q = q.reverse< @list[m] 17 | l = m + 1 18 | end 19 | end 20 | end 21 | 22 | (0..@m-1).each do |i| 23 | if binary(@t[i]) 24 | puts "1" 25 | else 26 | puts "0" 27 | end 28 | end -------------------------------------------------------------------------------- /lib/baekjoon/class3/id1992.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | @pan = [] 3 | @ans = [] 4 | (1..n).each do 5 | @pan<= j[0][0]: 15 | # heapq.heappush(tj, -heapq.heappop(j)[1]) 16 | # if tj: 17 | # a -= heapq.heappop(tj) 18 | # elif not j: 19 | # break 20 | # 21 | # print(a) 22 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id10989.rb: -------------------------------------------------------------------------------- 1 | # 시간 초과 python3 2 | # import sys 3 | # n = int(input()) 4 | # n_list = [0] * 10001 5 | # for i in range(n): 6 | # n_list[int(sys.stdin.readline())] += 1 7 | # for i in range(10001): 8 | # if n_list[i] != 0: 9 | # for j in range(n_list[i]): 10 | # print(i) 11 | 12 | count = gets.to_i 13 | array = [] 14 | (0..10000).each do 15 | array<<0 16 | end 17 | (1..count).each do 18 | array[gets.to_i]+=1 19 | end 20 | 21 | (0..10000).each do |i| 22 | if array[i] != 0 23 | (0..array[i]-1).each do 24 | puts i 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/baekjoon/class5/id17404.rb: -------------------------------------------------------------------------------- 1 | INF = 2147000000 2 | n = gets.to_i 3 | rgb = [] 4 | ans = INF 5 | (0...n).each do 6 | rgb << gets.chomp.split.map(&:to_i) 7 | end 8 | 9 | (0...3).each do |i| 10 | dp = [] 11 | (0...n).each do 12 | dp << [INF, INF, INF] 13 | end 14 | dp[0][i] = rgb[0][i] 15 | (1...n).each do |j| 16 | dp[j][0] = rgb[j][0] + [dp[j-1][1], dp[j-1][2]].min 17 | dp[j][1] = rgb[j][1] + [dp[j-1][0], dp[j-1][2]].min 18 | dp[j][2] = rgb[j][2] + [dp[j-1][0], dp[j-1][1]].min 19 | end 20 | (0...3).each do |j| 21 | if i != j 22 | ans = [ans, dp[-1][j]].min 23 | end 24 | end 25 | end 26 | 27 | puts ans 28 | -------------------------------------------------------------------------------- /lib/baekjoon/class5/id1208.rb: -------------------------------------------------------------------------------- 1 | @n, @s = gets.chomp.split.map(&:to_i) 2 | @nums = gets.chomp.split.map(&:to_i).to_a 3 | @res = 0 4 | @left_nums = {} 5 | def dfs(idx, e, add, side) 6 | if idx == e 7 | if side == 'L' 8 | if @left_nums.include? add 9 | @left_nums[add] += 1 10 | else 11 | @left_nums[add] = 1 12 | end 13 | elsif @left_nums.include? @s-add 14 | @res += @left_nums[@s-add] 15 | end 16 | return 17 | end 18 | dfs(idx+1, e, add+@nums[idx], side) 19 | dfs(idx+1, e, add, side) 20 | end 21 | dfs(0, (@n/2).to_i, 0, 'L') 22 | dfs((@n/2).to_i, @n, 0, 'R') 23 | if @s == 0 24 | @res -= 1 25 | end 26 | puts @res -------------------------------------------------------------------------------- /lib/baekjoon/page4/id4344.rb: -------------------------------------------------------------------------------- 1 | count = gets.to_i 2 | 3 | def total(string) 4 | all = 0 5 | 6 | (1..string.size).each do|i| 7 | all += string[i].to_i 8 | end 9 | 10 | all / (string[0].to_f) 11 | end 12 | 13 | (1..count).each do 14 | values = gets.chomp.split(" ") 15 | avg = total(values) 16 | up = 0 17 | 18 | (1..values.size - 1).each do |i| 19 | if avg < values[i].to_i 20 | up+=1 21 | end 22 | end 23 | 24 | car = ((up / (values[0].to_f)) * 100).round(3) 25 | if car * 1000 % 100 == 0 26 | puts "#{car}00%" 27 | elsif car * 1000 % 10 == 0 28 | puts "#{car}0%" 29 | else 30 | puts "#{car}%" 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id10504.rb: -------------------------------------------------------------------------------- 1 | sum = Array.new 2 | 3 | def count(n, sum) 4 | (2..44720).each do |i| 5 | tmp = n-sum[i] 6 | if tmp < 0 7 | return -1 8 | end 9 | if tmp%i == 0 10 | return i 11 | end 12 | end 13 | -1 14 | end 15 | 16 | sum << 0 17 | (1..44720).each do |i| 18 | sum[i] = sum[i-1]+i 19 | end 20 | tc = gets.to_i 21 | (1..tc).each do 22 | n = gets.to_i 23 | a = count(n, sum) 24 | if a == -1 25 | puts "IMPOSSIBLE" 26 | else 27 | print n 28 | print " = " 29 | b = (n-sum[a])/a 30 | (1..a-1).each do |i| 31 | print b+i 32 | print " + " 33 | end 34 | puts b+a 35 | end 36 | end 37 | 38 | -------------------------------------------------------------------------------- /lib/baekjoon/6000/id6549.rb: -------------------------------------------------------------------------------- 1 | while true 2 | rec =gets.chomp.split.map(&:to_i).to_a 3 | n = rec.shift 4 | 5 | if n == 0 6 | break 7 | end 8 | 9 | stack = [] 10 | answer = 0 11 | 12 | (0...n).each do |i| 13 | while (stack.length != 0) and (rec[stack[-1]] > rec[i]) 14 | @tmp = stack.pop 15 | @width = stack.length == 0 ? i : i - stack[-1] - 1 16 | answer = [answer, @width * rec[@tmp]].max 17 | end 18 | stack << i 19 | end 20 | 21 | while stack.length != 0 22 | @tmp = stack.pop 23 | @width = stack.length == 0 ? n : n - stack[-1] - 1 24 | answer = [answer, @width * rec[@tmp]].max 25 | end 26 | puts answer 27 | end 28 | -------------------------------------------------------------------------------- /lib/baekjoon/class5/id1197.rb: -------------------------------------------------------------------------------- 1 | v, e = gets.chomp.split.map(&:to_i) 2 | @v_root = Array(0..v+1) 3 | e_list = [] 4 | (0..e-1).each do 5 | e_list< e_root 23 | @v_root[s_root] = e_root 24 | else 25 | @v_root[e_root] = s_root 26 | end 27 | answer+=w 28 | end 29 | } 30 | puts answer -------------------------------------------------------------------------------- /lib/baekjoon/class4/id12851.rb: -------------------------------------------------------------------------------- 1 | n, k = gets.chomp.split.map(&:to_i) 2 | @visit = [] 3 | (0..100000).each do 4 | @visit << [-1, 0] 5 | end 6 | def bfs(n) 7 | q = [n] 8 | @visit[n][0] = 0 9 | @visit[n][1] = 1 10 | 11 | while q.length != 0 12 | x = q.shift 13 | [x-1, x+1, x*2].each { |i| 14 | if 0<=i && i<=100000 15 | if @visit[i][0] == -1 16 | @visit[i][0] = @visit[x][0] + 1 17 | @visit[i][1] = @visit[x][1] 18 | q< 0 18 | dp_next[e][bm | (1< j 14 | dp[i][j] = dp[i-1][j] 15 | else 16 | dp[i][j] = [dp[i-1][j], mem[i] + dp[i-1][j-cost[i]]].max 17 | end 18 | if dp[i][j] >= m 19 | res = [res, j].min 20 | end 21 | end 22 | end 23 | 24 | if m == 0 25 | puts 0 26 | elsif n == 1 27 | puts cost[0] 28 | elsif res == 2147483647 29 | puts n*m 30 | else 31 | puts res 32 | end 33 | -------------------------------------------------------------------------------- /lib/baekjoon/page5/id7579.rb: -------------------------------------------------------------------------------- 1 | n, m = gets.chomp.split.map(&:to_i) 2 | mem = gets.chomp.split.map(&:to_i).to_a 3 | cost = gets.chomp.split.map(&:to_i).to_a 4 | tc = cost.sum 5 | res = 2147483647 6 | dp = [] 7 | (0..n).each do 8 | dp << Array.new(tc+1, 0) 9 | end 10 | 11 | (0..n-1).each do |i| 12 | (0..tc-1).each do |j| 13 | if cost[i] > j 14 | dp[i][j] = dp[i-1][j] 15 | else 16 | dp[i][j] = [dp[i-1][j], mem[i] + dp[i-1][j-cost[i]]].max 17 | end 18 | if dp[i][j] >= m 19 | res = [res, j].min 20 | end 21 | end 22 | end 23 | 24 | if m == 0 25 | puts 0 26 | elsif n == 1 27 | puts cost[0] 28 | elsif res == 2147483647 29 | puts n*m 30 | else 31 | puts res 32 | end 33 | -------------------------------------------------------------------------------- /lib/baekjoon/class4/id1991.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | @tree = Hash.new 3 | (0..n-1).each do 4 | value = gets.chomp.split 5 | root, left, right = value[0], value[1], value[2] 6 | @tree[root] = [left, right] 7 | end 8 | 9 | def pre(root) 10 | unless root == '.' 11 | print(root) 12 | pre(@tree[root][0]) 13 | pre(@tree[root][1]) 14 | end 15 | end 16 | 17 | def ino(root) 18 | unless root == '.' 19 | ino @tree[root][0] 20 | print root 21 | ino @tree[root][1] 22 | end 23 | end 24 | 25 | def pos(root) 26 | unless root == '.' 27 | pos @tree[root][0] 28 | pos @tree[root][1] 29 | print root 30 | end 31 | end 32 | 33 | pre "A" 34 | puts 35 | ino "A" 36 | puts 37 | pos "A" 38 | -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1018.rb: -------------------------------------------------------------------------------- 1 | n, m = gets.chomp.split(" ").map(&:to_i) 2 | original = [] 3 | count = [] 4 | (0..n-1).each do 5 | original.append(gets.chomp) 6 | end 7 | 8 | (0..n-8).each do|a| 9 | (0..m-8).each do |b| 10 | index1 = 0 11 | index2 = 0 12 | (a..a+7).each do |i| 13 | (b..b+7).each do |j| 14 | if (i+j)%2 == 0 15 | if original[i][j] == 'W' 16 | index2 += 1 17 | else 18 | index1 += 1 19 | end 20 | else 21 | if original[i][j] == 'W' 22 | index1 += 1 23 | else 24 | index2 += 1 25 | end 26 | end 27 | end 28 | end 29 | count<<[index1, index2].min 30 | end 31 | end 32 | p count.min 33 | -------------------------------------------------------------------------------- /lib/baekjoon/class4/id11444.rb: -------------------------------------------------------------------------------- 1 | @p = 1000000007 2 | def multi(a, b) 3 | temp = [] 4 | (0..1).each do 5 | temp<<[0]*b[0].length 6 | end 7 | 8 | (0..1).each do |i| 9 | (0..b[0].length-1).each do |j| 10 | sum = 0 11 | (0..1).each do |k| 12 | sum += (a[i][k] * b[k][j]) 13 | end 14 | temp[i][j] = sum % @p 15 | end 16 | end 17 | temp 18 | end 19 | 20 | def power(adj, n) 21 | if n == 1 22 | adj 23 | elsif n % 2 != 0 24 | return multi(power(adj, n - 1), adj) 25 | else 26 | power(multi(adj, adj), (n/2).to_i) 27 | end 28 | end 29 | 30 | adj = [[1, 1], [1, 0]] 31 | start = [[1], [1]] 32 | n = gets.to_i 33 | if n < 3 34 | puts 1 35 | else 36 | puts multi(power(adj, n - 2), start)[0][0] 37 | end 38 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id10866.rb: -------------------------------------------------------------------------------- 1 | array = [] 2 | count = gets.to_i 3 | (1..count).each do 4 | text = gets.chomp.split(" ") 5 | if text[0] == "push_front" 6 | array.reverse! 7 | array << text[1] 8 | array.reverse! 9 | elsif text[0] == "push_back" 10 | array << text[1] 11 | elsif text[0] == "pop_front" 12 | array.reverse! 13 | puts array.empty? ? -1 : array.pop 14 | array.reverse! 15 | elsif text[0] == "pop_back" 16 | puts array.empty? ? -1 : array.pop 17 | elsif text[0] == "size" 18 | puts array.size 19 | elsif text[0] == "empty" 20 | puts array.empty? ? 1 : 0 21 | elsif text[0] == "front" 22 | puts array.empty? ? -1 : array[0] 23 | elsif text[0] == "back" 24 | puts array.empty? ? -1 : array[-1] 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/baekjoon/class4/id1918.rb: -------------------------------------------------------------------------------- 1 | strn = gets.chomp.split("").to_a 2 | stack = [] 3 | res = '' 4 | strn.each do |s| 5 | if s.match(/[a-zA-Z]/) 6 | res += s 7 | else 8 | if s == '(' 9 | stack<= 0 9 | puts k.round 10 | else 11 | k *= -1 12 | puts k.round * -1 13 | end 14 | 15 | nums.sort! 16 | puts nums[((n-1)/2).to_i] 17 | counts = Hash.new 18 | (1..n).each do |i| 19 | counts[i]=[] 20 | end 21 | mc = 1 22 | c = 1 23 | (1..n-1).each do |j| 24 | if nums[j] == nums[j-1] 25 | c+=1 26 | else 27 | counts[c]< 0 and @p_value[i] != @p_value[j] 13 | j = p[j - 1] 14 | end 15 | if @p_value[i] == @p_value[j] 16 | j+=1 17 | p[i] = j 18 | end 19 | end 20 | p 21 | end 22 | 23 | def work(p) 24 | result = [] 25 | c = 0 26 | j = 0 27 | (0..@t_value.length).each do |i| 28 | while j>0 and @t_value[i] != @p_value[j] 29 | j = p[j-1] 30 | end 31 | if @t_value[i] == @p_value[j] 32 | if j == (@p_value.length-1) 33 | result.append(i-@p_value.length+2) 34 | c += 1 35 | j = p[j] 36 | else 37 | j+=1 38 | end 39 | end 40 | end 41 | puts c 42 | result.each do |l| 43 | puts l 44 | end 45 | end 46 | 47 | work(get_value) 48 | -------------------------------------------------------------------------------- /lib/baekjoon/1000/id1071.rb: -------------------------------------------------------------------------------- 1 | n = gets.to_i 2 | arr = gets.chomp.split.map(&:to_i) 3 | num_cnt = [0] * 1005 4 | arr.each do |num| 5 | num_cnt[num] += 1 6 | end 7 | 8 | cur = 0 9 | result = [] 10 | while num_cnt.sum > 0 11 | if num_cnt[cur] != 0 12 | if num_cnt[cur+1] != 0 13 | bool = false 14 | ((cur+2)...1001).each do |next_num| 15 | if num_cnt[next_num] != 0 16 | result += ([cur] * num_cnt[cur]) 17 | result << next_num 18 | num_cnt[cur] = 0 19 | num_cnt[next_num] -= 1 20 | bool = true 21 | break 22 | end 23 | end 24 | unless bool 25 | result += ([cur + 1] * num_cnt[cur + 1]) 26 | result += ([cur] * num_cnt[cur]) 27 | num_cnt[cur] = 0 28 | num_cnt[cur + 1] = 0 29 | end 30 | else 31 | while num_cnt[cur] != 0 32 | result << cur 33 | num_cnt[cur] -= 1 34 | end 35 | end 36 | end 37 | cur += 1 38 | end 39 | puts result.join(" ") 40 | -------------------------------------------------------------------------------- /lib/baekjoon/class3/id1260.rb: -------------------------------------------------------------------------------- 1 | @n, m, v = gets.split.map(&:to_i) 2 | @graph = [] 3 | (0..@n).each do 4 | @graph << [] 5 | end 6 | @a_bfs = [] 7 | @a_dfs = [] 8 | 9 | (0..m-1).each do 10 | a, b = gets.split.map(&:to_i) 11 | @graph[a]< lst[mid] 16 | low = mid + 1 17 | end 18 | end 19 | high 20 | end 21 | 22 | (0...n).each do |i| 23 | a, b = gets.chomp.split.map(&:to_i) 24 | dic[b] = a 25 | end 26 | 27 | temp = dic.sort 28 | temp.each { |a, i| 29 | lst << i 30 | } 31 | 32 | lst.each { |i| 33 | if i > lis[-1] 34 | lis< pypy3 2 | # n = int(input()) 3 | # 4 | # ans = 0 5 | # row = [0] * n 6 | # 7 | # def is_promising(x): 8 | # for i in range(x): 9 | # if row[x] == row[i] or abs(row[x] - row[i]) == abs(x - i): 10 | # return False 11 | # return True 12 | # 13 | # 14 | # def n_queens(x): 15 | # global ans 16 | # if x == n: 17 | # ans += 1 18 | # else: 19 | # for i in range(n): 20 | # row[x] = i 21 | # if is_promising(x): 22 | # n_queens(x + 1) 23 | # 24 | # 25 | # n_queens(0) 26 | # print(ans) 27 | # 28 | @n = gets.to_i 29 | @ans = 0 30 | @row = [0] * @n 31 | def is_p(x) 32 | (0...x).each do |i| 33 | if @row[x] == @row[i] or (@row[x] - @row[i]).abs == (x - i).abs 34 | return false 35 | end 36 | end 37 | true 38 | end 39 | 40 | def n_q(x) 41 | if x == @n 42 | @ans += 1 43 | else 44 | (0...@n).each do |i| 45 | @row[x] = i 46 | if is_p(x) 47 | n_q(x+1) 48 | end 49 | end 50 | end 51 | end 52 | 53 | n_q(0) 54 | puts @ans 55 | -------------------------------------------------------------------------------- /.idea/Start.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | -------------------------------------------------------------------------------- /lib/baekjoon/class3/id1074.rb: -------------------------------------------------------------------------------- 1 | # python 2 | # n, r, c = map(int, input().split()) 3 | # cnt = 0 4 | # 5 | # 6 | # def start(x, y, l): 7 | # global cnt 8 | # 9 | # if x == r and y == c: 10 | # print(cnt) 11 | # exit(0) 12 | # elif l == 1: 13 | # cnt += 1 14 | # return 15 | # elif not (x <= r <= x + l and y <= c <= y + l): 16 | # cnt += l * l 17 | # return 18 | # 19 | # l //= 2 20 | # start(x, y, l) 21 | # start(x, y + l, l) 22 | # start(x + l, y, l) 23 | # start(x + l, y + l, l) 24 | # 25 | # 26 | # start(0, 0, 2 ** n) 27 | # print(cnt) 28 | # 29 | @n, @r, @c = gets.split.map(&:to_i) 30 | @cnt = 0 31 | 32 | def start(x, y, l) 33 | if x == @r and y == @c 34 | puts @cnt 35 | exit(0) 36 | end 37 | 38 | if l == 1 39 | @cnt += 1 40 | return 41 | end 42 | 43 | unless x <= @r and @r <= x + 1 and y <= @c and @c <= y + l 44 | @cnt += (l * l) 45 | return 46 | end 47 | l = (l/2).to_i 48 | start(x, y, l) 49 | start(x, y + l, l) 50 | start(x + l, y, l) 51 | start(x + l, y + l, l) 52 | end 53 | 54 | start(0, 0, 2**@n) 55 | puts @cnt 56 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2022 PersesTitan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/baekjoon/10000/id18111.rb: -------------------------------------------------------------------------------- 1 | # 시간 초과 pypy3 2 | # import sys 3 | # a = sys.maxsize 4 | # n, m, b = map(int, sys.stdin.readline().split()) 5 | # g = [list(map(int, sys.stdin.readline().split())) for _ in range(n)] 6 | # he = 0 7 | # for target in range(257): 8 | # max_, min_ = 0, 0 9 | # for i in range(n): 10 | # for j in range(m): 11 | # if g[i][j] >= target: 12 | # max_ += g[i][j] - target 13 | # else: 14 | # min_ += target - g[i][j] 15 | # if max_ + b >= min_: 16 | # if min_ + (max_ * 2) <= a: 17 | # a = min_ + (max_ * 2) 18 | # he = target 19 | # print(a, he) 20 | index = 0 21 | max_time = 10000000000000 22 | n, m, b = gets.split.map(&:to_i) 23 | g = [] 24 | (1..n).each do 25 | g<= t 33 | max += (g[i][j] - t) 34 | else 35 | min += (t - g[i][j]) 36 | end 37 | end 38 | end 39 | 40 | if (max + b) < min 41 | next 42 | end 43 | time = 2*max + min 44 | if time<=max_time 45 | max_time = time 46 | index = t 47 | end 48 | end 49 | puts "#{max_time} #{index}" 50 | -------------------------------------------------------------------------------- /lib/baekjoon/class3/id1780.rb: -------------------------------------------------------------------------------- 1 | # 시간 초과 pypy3 2 | # n = int(input()) 3 | # pan = [list(map(int, input().split())) for _ in range(n)] 4 | # answer = [0, 0, 0] 5 | # 6 | # def start(x, y, l): 7 | # num = pan[x][y] 8 | # 9 | # for i in range(x, x + l): 10 | # for j in range(y, y + l): 11 | # 12 | # if pan[i][j] != num: 13 | # l //= 3 14 | # for k in range(3): 15 | # for h in range(3): 16 | # start(x + (k * l), y + (h * l), l) 17 | # return 18 | # answer[num] += 1 19 | # 20 | # start(0, 0, n) 21 | # 22 | # print(answer[-1]) 23 | # print(answer[0]) 24 | # print(answer[1]) 25 | # 26 | n = gets.to_i 27 | @pan = [] 28 | (1..n).each do 29 | @pan << gets.split.map(&:to_i) 30 | end 31 | @ans = [0, 0, 0] 32 | 33 | def start(x, y, l) 34 | num = @pan[x][y] 35 | (x..x+l-1).each { |i| 36 | (y..y+l-1).each do |j| 37 | if @pan[i][j] != num 38 | l = (l/3).to_i 39 | (0..2).each do |k| 40 | (0..2).each do |h| 41 | start(x+(k*l), y+(h*l), l) 42 | end 43 | end 44 | return 45 | end 46 | end 47 | } 48 | @ans[num] += 1 49 | end 50 | 51 | start(0, 0, n) 52 | puts @ans[-1] 53 | puts @ans[0] 54 | puts @ans[1] 55 | 56 | -------------------------------------------------------------------------------- /lib/baekjoon/4000/id4949.rb: -------------------------------------------------------------------------------- 1 | # 런타임 에러... -> pypy3 2 | # while True: 3 | # line = input() 4 | # st = [] 5 | # if line == ".": 6 | # break 7 | # for i in line: 8 | # if i == "[" or i == "(": 9 | # st.append(i) 10 | # elif i == "]": 11 | # if len(st) != 0 and st[-1] == '[': 12 | # st.pop() 13 | # else: 14 | # st.append(']') 15 | # break 16 | # elif i == ')': 17 | # if len(st) != 0 and st[-1] == '(': 18 | # st.pop() 19 | # else: 20 | # st.append(")") 21 | # break 22 | # if len(st) == 0: 23 | # print("yes") 24 | # else: 25 | # print("no") 26 | 27 | while true 28 | line = gets.chomp.split("") 29 | st = [] 30 | if line == "." 31 | break 32 | end 33 | line.each do |i| 34 | if i == "(" || i == "[" 35 | st<= 2.3.0") 14 | 15 | spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" 16 | 17 | spec.metadata["homepage_uri"] = spec.homepage 18 | spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here." 19 | spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." 20 | 21 | # Specify which files should be added to the gem when it is released. 22 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 23 | spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do 24 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 25 | end 26 | spec.bindir = "exe" 27 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 28 | spec.require_paths = ["lib"] 29 | end 30 | -------------------------------------------------------------------------------- /lib/baekjoon/class5/id2098.rb: -------------------------------------------------------------------------------- 1 | #import sys 2 | # 3 | # N = int(input()) 4 | # path = [list(map(int, input().split())) for _ in range(N)] 5 | # dp = [[0] * (1 << N) for _ in range(N)] 6 | # MAX = sys.maxsize 7 | # 8 | # 9 | # def dfs(a, t): 10 | # if dp[a][t]: 11 | # return dp[a][t] 12 | # 13 | # if t == (1 << N) - 1: 14 | # return path[a][0] if path[a][0] > 0 else MAX 15 | # 16 | # cost = MAX 17 | # for i in range(1, N): 18 | # if not t & (1 << i) and path[a][i]: 19 | # val = dfs(i, t | (1 << i)) 20 | # cost = min(cost, val + path[a][i]) 21 | # 22 | # dp[a][t] = cost 23 | # return dp[a][t] 24 | # 25 | # 26 | # print(dfs(0, 1)) 27 | 28 | # 출력 문제 python 29 | # t = gets.to_i 30 | # (1..t).each do 31 | # n = gets.to_i 32 | # point = [] 33 | # tx = 0 34 | # ty = 0 35 | # (0..n-1).each do 36 | # x, y = gets.chomp.split.map(&:to_i) 37 | # point << [x, y] 38 | # tx += x 39 | # ty += y 40 | # end 41 | # ret = 2147483647 42 | # com = point.combination((n/2).to_i).to_a 43 | # com_l = (com.length/2).to_i 44 | # 45 | # com[..com_l].each { |el| 46 | # x1_t = 0 47 | # y1_t = 0 48 | # (el).each { |va| 49 | # x1, y2 = va[0], va[1] 50 | # x1_t += x1 51 | # y1_t += y2 52 | # } 53 | # x2_t = tx - x1_t 54 | # y2_t = ty - y1_t 55 | # ret = [ret, Math.sqrt((x1_t - x2_t) ** 2 + (y1_t - y2_t) ** 2)].min 56 | # } 57 | # puts ret 58 | # end 59 | -------------------------------------------------------------------------------- /lib/baekjoon/class3/id1389.rb: -------------------------------------------------------------------------------- 1 | # python 2 | # from collections import deque 3 | # 4 | # n, m = map(int, input().split()) 5 | # g = [[] for _ in range(n + 1)] 6 | # ans = [] 7 | # 8 | # for _ in range(m): 9 | # a, b = map(int, input().split()) 10 | # g[a].append(b) 11 | # g[b].append(a) 12 | # 13 | # 14 | # def bfs(x, step): 15 | # visited = [False] * (n + 1) 16 | # visited[x] = True 17 | # step_arr = [0] * (n + 1) 18 | # q = deque([(x, step)]) 19 | # 20 | # while q: 21 | # node, step = q.popleft() 22 | # 23 | # step_arr[node] = step 24 | # 25 | # for index in g[node]: 26 | # if not visited[index]: 27 | # visited[index] = True 28 | # q.append((index, step + 1)) 29 | # ans.append(sum(step_arr)) 30 | # 31 | # 32 | # for i in range(1, len(g)): 33 | # bfs(i, 0) 34 | # print(ans.index(min(ans)) + 1) 35 | @n, m = gets.split.map(&:to_i) 36 | @graph = [] 37 | (0..@n).each do 38 | @graph<<[] 39 | end 40 | @ans = [] 41 | 42 | (0..m-1).each do 43 | a, b = gets.split.map(&:to_i) 44 | @graph[a]<= m: 19 | # return 20 | # 21 | # x = find(x) 22 | # y = find(y) 23 | # prt[x] = y 24 | # 25 | # 26 | # def upper_b(x): 27 | # s, e = 0, m 28 | # while s < e: 29 | # mid = (s + e) // 2 30 | # if nums[mid] > x: 31 | # e = mid 32 | # else: 33 | # s = mid + 1 34 | # return e 35 | # 36 | # 37 | # for num in seq: 38 | # idx = find(upper_b(num)) 39 | # print(nums[idx]) 40 | # uni(idx, idx + 1) 41 | n, @m, k = gets.chomp.split.map(&:to_i) 42 | @nums = gets.chomp.split.map(&:to_i).sort 43 | @prt = [] 44 | (0..@m).each do |i| @prt << i end 45 | seq = gets.chomp.split.map(&:to_i).to_a 46 | 47 | def find(x) 48 | if x == @prt[x] 49 | return x 50 | end 51 | v = find(@prt[x]) 52 | @prt[x] = v 53 | v 54 | end 55 | 56 | def union(x, y) 57 | if y >= @m 58 | return 59 | end 60 | x = find(x) 61 | y = find(y) 62 | @prt[x] = y 63 | end 64 | 65 | def upper_b(x) 66 | s, e = 0, @m 67 | while s x 70 | e = mid 71 | else 72 | s = mid + 1 73 | end 74 | end 75 | e 76 | end 77 | 78 | seq.each { |num| 79 | idx = upper_b(num) 80 | idx = find(idx) 81 | puts @nums[idx] 82 | union(idx, idx+1) 83 | } 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Start 2 | 3 | Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/Start`. To experiment with that code, run `bin/console` for an interactive prompt. 4 | 5 | TODO: Delete this and the text above, and describe your gem 6 | 7 | ## Installation 8 | 9 | Add this line to your application's Gemfile: 10 | 11 | ```ruby 12 | gem 'Start' 13 | ``` 14 | 15 | And then execute: 16 | 17 | $ bundle install 18 | 19 | Or install it yourself as: 20 | 21 | $ gem install Start 22 | 23 | ## Usage 24 | 25 | TODO: Write usage instructions here 26 | 27 | ## Development 28 | 29 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 30 | 31 | To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 32 | 33 | ## Contributing 34 | 35 | Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/Start. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/Start/blob/master/CODE_OF_CONDUCT.md). 36 | 37 | 38 | ## License 39 | 40 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 41 | 42 | ## Code of Conduct 43 | 44 | Everyone interacting in the Start project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/Start/blob/master/CODE_OF_CONDUCT.md). 45 | -------------------------------------------------------------------------------- /lib/baekjoon/class5/id2887.rb: -------------------------------------------------------------------------------- 1 | # 시간초과 pypy3 2 | # import sys 3 | # 4 | # input = sys.stdin.readline 5 | # n = int(input()) 6 | # xlst, ylst, zlst = [], [], [] 7 | # 8 | # 9 | # def find(x): 10 | # if x != par[x]: 11 | # par[x] = find(par[x]) 12 | # return par[x] 13 | # 14 | # 15 | # def uni(x, y): 16 | # par[find(y)] = find(x) 17 | # 18 | # 19 | # for i in range(n): 20 | # x, y, z = map(int, input().split()) 21 | # xlst.append((x, i)) 22 | # ylst.append((y, i)) 23 | # zlst.append((z, i)) 24 | # xlst.sort() 25 | # ylst.sort() 26 | # zlst.sort() 27 | # 28 | # ed = [] 29 | # for curList in xlst, ylst, zlst: 30 | # for i in range(1, n): 31 | # w1, a = curList[i - 1] 32 | # w2, b = curList[i] 33 | # ed.append((abs(w1 - w2), a, b)) 34 | # ed.sort(reverse=True) 35 | # 36 | # par = [i for i in range(n + 1)] 37 | # cnt, ans = n - 1, 0 38 | # while cnt: 39 | # w, a, b = ed.pop() 40 | # if find(a) == find(b): 41 | # continue 42 | # uni(a, b) 43 | # cnt -= 1 44 | # ans += w 45 | # print(ans) 46 | n = gets.to_i 47 | x_lst,y_lst,z_lst = [],[],[] 48 | @parents = [] 49 | (0..n+1).each do |i| @parents< 0 ? x+1 : x-1 29 | x2 = a[0] > 0 ? x+1 : x 30 | y1 = a[0]*a[1] > 0 ? y+1 : y-1 31 | y2 = a[0]*a[1] > 0 ? y+1 : y 32 | y_nx = (pos[1]+a[1] * (x2-pos[0])) 33 | x_ny = (pos[0]+((y2-pos[1]) / a[1])) 34 | if y+10**-7 < y_nx && y_nx < y+1-10**-7 && (x_ny < x - 10**-7 || x_ny > x+1+10**-7) 35 | pos = [x2, y_nx] 36 | search(x1, y, pos, a) 37 | elsif x + 10**-7 < x_ny && x_ny < x+1-10**-7 && (y-10**-7 > y_nx || y_nx > y+1+10**-7) 38 | pos = [x_ny, y2] 39 | search(x, y1, pos, a) 40 | else 41 | pos = [x2, y2] 42 | if a[1] > 0 && vertical(x1, y) 43 | @position << pos 44 | end 45 | if a[1] < 0 && height(x, y1) 46 | @position << pos 47 | end 48 | search(x1, y1, pos, a) 49 | if a[1] > 0 && height(x, y1) 50 | @position << pos 51 | end 52 | if a[1] < 0 && vertical(x1, y) 53 | @position << pos 54 | end 55 | end 56 | end 57 | end 58 | 59 | 60 | (0..@height-1).each do |i| 61 | (0..@vertical-1).each do |j| 62 | if @box[i][j] == '*' 63 | @x_axis = j 64 | @y_axis = i 65 | white = [j+0.5, i+0.5] 66 | elsif @box[i][j] == '#' 67 | count += 1 68 | end 69 | end 70 | end 71 | 72 | (0..1).each do |i| 73 | (0..1).each do |j| 74 | j = @vertical * j 75 | i = @height * i 76 | item = [j-white[0]>0 ? 1 : -1, (i-white[1])/(j-white[0])] 77 | i_list< 0 ? 1 : -1, (i-white[1])/(j-white[0])] 83 | unless i_list.include? item 84 | i_list< 0 ? (x + 1) : (x - 1) 22 | x2 = angle[0] > 0 ? (x + 1) : (x) 23 | y1 = angle[0] * angle[1] > 0 ? (y + 1) : (y - 1) 24 | y2 = angle[0] * angle[1] > 0 ? (y + 1) : (y) 25 | y_nx = (pos[1] + (angle[1]) * (x2 - pos[0])) 26 | x_ny = (pos[0] + ((y2 - pos[1]) / (angle[1]))) 27 | if y + 1e-7 < y_nx and y_nx < y + 1 - 1e-7 and (x_ny < x - 1e-7 or x_ny > x + 1 + 1e-7) 28 | pos = [x2, y_nx] 29 | search(x1, y, pos, angle) 30 | elsif x + 1e-7 < x_ny and x_ny < x + 1 - 1e-7 and (y - 1e-7 > y_nx or y_nx > y + 1 + 1e-7) 31 | pos = [x_ny, y2] 32 | search(x, y1, pos, angle) 33 | else 34 | pos = [x2, y2] 35 | if angle[1] > 0 and (x1 == -1 or x1 == @vertical or @box[y][x1] == '#') 36 | @position << pos 37 | end 38 | if angle[1] < 0 and (y1 == -1 or y1 == @height or @box[y1][x] == '#') 39 | @position << pos 40 | end 41 | search(x1, y1, pos, angle) 42 | if angle[1] > 0 and (y1 == -1 or y1 == @height or @box[y1][x] == '#') 43 | @position << pos 44 | end 45 | if angle[1] < 0 and (x1 == -1 or x1 == @vertical or @box[y][x1] == '#') 46 | @position << pos 47 | end 48 | end 49 | puts @position.to_s 50 | end 51 | end 52 | 53 | (0..@height-1).each do |i| 54 | (0..@vertical-1).each do |j| 55 | if @box[i][j] == '*' 56 | x = j 57 | y = i 58 | Light = [j+0.5, i+0.5] 59 | elsif @box[i][j] == '#' 60 | count += 1 61 | end 62 | end 63 | end 64 | (0..1).each do |i| 65 | (0..1).each do |j| 66 | slope = [] 67 | j = @vertical * j 68 | i = @height * i 69 | slope = [j-Light[0]>0 ? 1 : -1, (i - Light[1]) / (j - Light[0])] 70 | slopeList< 0 ? 1 : -1, (i - Light[1]) / (j - Light[0])] 76 | unless slope.include? slopeList 77 | slopeList< W 47 | # INF 48 | # end 49 | # dp = [] 50 | # (0..(N/3)).each do 51 | # dp << arr 52 | # end 53 | # dp[0][OUT] = dp[0][IN] = 1 54 | # dp[0][BOTH] = 2 55 | # outer_cpy = outer 56 | # inner_cpy = inner 57 | # outer_cpy[0] = outer_cpy[N-1] = INF 58 | # f(dp, outer_cpy, inner_cpy) 59 | # dp[N-1][IN] 60 | # end 61 | # 62 | # def case3(outer, inner) 63 | # if inner[0] + inner[N-1] > W 64 | # return INF 65 | # end 66 | # dp = [] 67 | # (0..(N/3)).each do 68 | # dp << arr 69 | # end 70 | # dp[0][OUT] = dp[0][IN] = 1 71 | # dp[0][BOTH] = 2 72 | # outer_cpy = outer 73 | # inner_cpy = inner 74 | # inner_cpy[0] = inner_cpy[N-1] = INF 75 | # f(dp, outer_cpy, inner_cpy) 76 | # dp[N-1][OUT] 77 | # end 78 | # 79 | # def case4(outer, inner) 80 | # if outer[0] + outer[N-1] > W 81 | # return INF 82 | # end 83 | # if inner[0] + inner[N-1] > W 84 | # return INF 85 | # end 86 | # dp = [] 87 | # (0..(N/3)).each do 88 | # dp << arr 89 | # end 90 | # dp[0][OUT] = dp[0][IN] = 1 91 | # dp[0][BOTH] = 2 92 | # outer_cpy = outer 93 | # inner_cpy = inner 94 | # outer_cpy[0] = outer_cpy[N-1] = INF 95 | # inner_cpy[0] = inner_cpy[N-1] = INF 96 | # f(dp, outer_cpy, inner_cpy) 97 | # dp[N-2][BOTH] 98 | # end 99 | # 100 | # miis = gets.chomp.split(" ") 101 | # (0..T).each do 102 | # N = miis[0].to_i 103 | # W = miis[1].to_i 104 | # outer = [] 105 | # inner = [] 106 | # gets.chomp.split(" ").each { |v| 107 | # outer< par_y: 21 | # par1[par_x] = par_y 22 | # elif par_y > par_x: 23 | # par1[par_y] = par_x 24 | # 25 | # 26 | # def cs(p1, p2, p3): 27 | # temp = (p1[0] * p2[1]) + (p2[0] * p3[1]) + (p3[0] * p1[1]) 28 | # temp = temp - (p1[1] * p2[0]) - (p2[1] * p3[0]) - (p3[1] * p1[0]) 29 | # if temp > 0: 30 | # return 1 31 | # elif temp < 0: 32 | # return -1 33 | # else: 34 | # return 0 35 | # 36 | # def get_bool(l1, l2, l3, l4): 37 | # for i in range(0, 2): 38 | # if l1[i] > l3[i] and l1[i] > l4[i] and l2[i] > l3[i] and l2[i] > l4[i]: 39 | # return True 40 | # if l1[i] < l3[i] and l1[i] < l4[i] and l2[i] < l3[i] and l2[i] < l4[i]: 41 | # return True 42 | # return False 43 | # 44 | # def check(li1, li2): 45 | # l1 = [li1[0], li1[1]] 46 | # l2 = [li1[2], li1[3]] 47 | # l3 = [li2[0], li2[1]] 48 | # l4 = [li2[2], li2[3]] 49 | # result1 = cs(l1, l2, l3) * cs(l1, l2, l4) 50 | # result2 = cs(l3, l4, l1) * cs(l3, l4, l2) 51 | # if result1 <= 0 and result2 <= 0: 52 | # if not get_bool(l1, l2, l3, l4): 53 | # return True 54 | # return False 55 | # 56 | # 57 | # for i in range(n): 58 | # s.append(list(map(int, input().split()))) 59 | # par1.append(i) 60 | # par2.append(0) 61 | # for i in range(n - 1): 62 | # for j in range(i + 1, n): 63 | # if check(s[i], s[j]): 64 | # union(i, j) 65 | # cnt = 0 66 | # max_num = 0 67 | # for i in range(n): 68 | # if par1[i] == i: 69 | # cnt += 1 70 | # par2[get_par(i)] += 1 71 | # max_num = max(max_num, (par2[get_par(i)])) 72 | # print(cnt) 73 | # print(max_num) 74 | 75 | n = gets.to_i 76 | s, @par1, @par2 = [], [], [] 77 | 78 | def get_par(a) 79 | if @par1[a] == a 80 | a 81 | else 82 | get_par(@par1[a]) 83 | end 84 | end 85 | 86 | def union(x, y) 87 | par_x = get_par(x) 88 | par_y = get_par(y) 89 | if par_x > par_y 90 | @par1[par_x] = par_y 91 | elsif par_y > par_x 92 | @par1[par_y] = par_x 93 | end 94 | end 95 | 96 | def cs(p1, p2, p3) 97 | temp = (p1[0] * p2[1]) + (p2[0] * p3[1]) + (p3[0] * p1[1]) - 98 | (p1[1] * p2[0]) - (p2[1] * p3[0]) - (p3[1] * p1[0]) 99 | if temp > 0 100 | 1 101 | elsif temp < 0 102 | -1 103 | else 104 | 0 105 | end 106 | end 107 | 108 | def get_bool(l1, l2, l3, l4) 109 | (0..1).each do|i| 110 | if l1[i] > l3[i] and l1[i] > l4[i] and l2[i] > l3[i] and l2[i] > l4[i] 111 | return true 112 | end 113 | end 114 | (0..1).each do|i| 115 | if l1[i] < l3[i] and l1[i] < l4[i] and l2[i] < l3[i] and l2[i] < l4[i] 116 | return true 117 | end 118 | end 119 | false 120 | end 121 | 122 | def check(li1, li2) 123 | l1 = li1[0..1] 124 | l2 = li1[2..3] 125 | l3 = li2[0..1] 126 | l4 = li2[2..3] 127 | result1 = cs(l1, l2, l3) * cs(l1, l2, l4) 128 | result2 = cs(l3, l4, l1) * cs(l3, l4, l2) 129 | 130 | if result1 <= 0 and result2 <= 0 131 | unless get_bool(l1, l2, l3, l4) 132 | return true 133 | end 134 | end 135 | false 136 | end 137 | 138 | (0...n).each do |i| 139 | s << gets.chomp.split.map(&:to_i) 140 | @par1 << i 141 | @par2 << 0 142 | end 143 | 144 | (0...n-1).each do |i| 145 | (i+1...n).each do |j| 146 | if check(s[i], s[j]) 147 | union(i, j) 148 | end 149 | end 150 | end 151 | 152 | cnt = 0 153 | max_num = 0 154 | (0...n).each do|i| 155 | if @par1[i] == i 156 | cnt += 1 157 | end 158 | max_num = [max_num, (@par2[get_par(i)] += 1)].max 159 | end 160 | 161 | puts cnt 162 | puts max_num 163 | --------------------------------------------------------------------------------