ngng628's Library

This documentation is automatically generated by online-judge-tools/verification-helper

:x: verify/utils/fastin.test.cr

Depends on

Code

# verification-helper: PROBLEM https://judge.yosupo.jp/problem/many_aplusb

require "../../src/nglib/utils/fastin"

t = NgLib::FastIn::Scanner.read_i32

ans = String.build { |io|
  t.times do
    a = NgLib::FastIn::Scanner.read_i64
    b = NgLib::FastIn::Scanner.read_i64
    io << a + b << '\n'
  end
}

print ans
# verification-helper: PROBLEM https://judge.yosupo.jp/problem/many_aplusb

# require "../../src/nglib/utils/fastin"
module NgLib
  module FastIn
    extend self

    lib LibC
      fun getchar = getchar_unlocked : Char
    end

    module Scanner
      extend self

      {% for int_t in Int::Primitive.union_types %}
        {% if Int::Signed.union_types.includes?(int_t) %}
        def read_{{ int_t.name.downcase[0..0] }}{{ int_t.name.downcase[3...int_t.name.size] }}(offset = 0)
        {% else %}
        def read_{{ int_t.name.downcase[0..0] }}{{ int_t.name.downcase[4...int_t.name.size] }}(offset = 0)
        {% end %}
          c = next_char
          res = {{ int_t }}.new(c.ord - '0'.ord)
          sgn = 1

          case c
          when '-'
            res = {{ int_t }}.new(LibC.getchar.ord - '0'.ord)
            sgn = -1
          when '+'
            res = {{ int_t }}.new(LibC.getchar.ord - '0'.ord)
          end

          until ascii_voidchar?(c = LibC.getchar)
            res = res*10 + (c.ord - '0'.ord)
          end

          res * sgn + offset
        end
      {% end %}

      def read_char : Char
        next_char
      end

      def read_word : String
        c = next_char
        s = [c]
        until ascii_voidchar?(c = LibC.getchar)
          s << c
        end
        s.join
      end

      private def next_char : Char
        c = '_'
        while ascii_voidchar?(c = LibC.getchar)
        end
        c
      end

      private def ascii_voidchar?(c)
        c.ascii_whitespace? || c.ord == -1
      end
    end
  end
end

t = NgLib::FastIn::Scanner.read_i32

ans = String.build { |io|
  t.times do
    a = NgLib::FastIn::Scanner.read_i64
    b = NgLib::FastIn::Scanner.read_i64
    io << a + b << '\n'
  end
}

print ans
Back to top page