kyopro-lib

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

View on GitHub

:x: test/yukicoder/782/main.test.cpp

Depends on

Code

#define PROBLEM "https://yukicoder.me/problems/no/782"

#include <iostream>
#include "Mylib/IO/input_tuples.cpp"
#include "Mylib/IO/join.cpp"
#include "Mylib/Misc/convert_base.cpp"

namespace hl = haar_lib;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int T, B;
  std::cin >> T >> B;
  for (auto [N] : hl::input_tuples<int>(T)) {
    auto ans = hl::convert_base_to(N, B);

    std::cout << hl::join(ans.begin(), ans.end(), "") << "\n";
  }

  return 0;
}
#line 1 "test/yukicoder/782/main.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/782"

#include <iostream>
#line 2 "Mylib/IO/input_tuples.cpp"
#include <initializer_list>
#line 4 "Mylib/IO/input_tuples.cpp"
#include <tuple>
#include <utility>
#include <vector>
#line 6 "Mylib/IO/input_tuple.cpp"

namespace haar_lib {
  template <typename T, size_t... I>
  static void input_tuple_helper(std::istream &s, T &val, std::index_sequence<I...>) {
    (void) std::initializer_list<int>{(void(s >> std::get<I>(val)), 0)...};
  }

  template <typename T, typename U>
  std::istream &operator>>(std::istream &s, std::pair<T, U> &value) {
    s >> value.first >> value.second;
    return s;
  }

  template <typename... Args>
  std::istream &operator>>(std::istream &s, std::tuple<Args...> &value) {
    input_tuple_helper(s, value, std::make_index_sequence<sizeof...(Args)>());
    return s;
  }
}  // namespace haar_lib
#line 8 "Mylib/IO/input_tuples.cpp"

namespace haar_lib {
  template <typename... Args>
  class InputTuples {
    struct iter {
      using value_type = std::tuple<Args...>;
      value_type value;
      bool fetched = false;
      int N, c = 0;

      value_type operator*() {
        if (not fetched) {
          std::cin >> value;
        }
        return value;
      }

      void operator++() {
        ++c;
        fetched = false;
      }

      bool operator!=(iter &) const {
        return c < N;
      }

      iter(int N) : N(N) {}
    };

    int N;

  public:
    InputTuples(int N) : N(N) {}

    iter begin() const { return iter(N); }
    iter end() const { return iter(N); }
  };

  template <typename... Args>
  auto input_tuples(int N) {
    return InputTuples<Args...>(N);
  }
}  // namespace haar_lib
#line 3 "Mylib/IO/join.cpp"
#include <sstream>
#include <string>

namespace haar_lib {
  template <typename Iter>
  std::string join(Iter first, Iter last, std::string delim = " ") {
    std::stringstream s;

    for (auto it = first; it != last; ++it) {
      if (it != first) s << delim;
      s << *it;
    }

    return s.str();
  }
}  // namespace haar_lib
#line 2 "Mylib/Misc/convert_base.cpp"
#include <algorithm>
#line 4 "Mylib/Misc/convert_base.cpp"

namespace haar_lib {
  std::vector<int64_t> convert_base_to(int64_t val, int64_t base) {
    if (val == 0) return {0};

    int b = std::abs(base);

    std::vector<int64_t> ret;
    while (val != 0) {
      int r = val % b;
      if (r < 0) r += b;
      val = (val - r) / base;
      ret.push_back(r);
    }

    std::reverse(ret.begin(), ret.end());

    return ret;
  }

  int64_t convert_base_from(const std::vector<int64_t> &val, int64_t base) {
    int64_t ret = 0;
    for (auto it = val.begin(); it != val.end(); ++it) {
      (ret *= base) += *it;
    }

    return ret;
  }
}  // namespace haar_lib
#line 7 "test/yukicoder/782/main.test.cpp"

namespace hl = haar_lib;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int T, B;
  std::cin >> T >> B;
  for (auto [N] : hl::input_tuples<int>(T)) {
    auto ans = hl::convert_base_to(N, B);

    std::cout << hl::join(ans.begin(), ans.end(), "") << "\n";
  }

  return 0;
}
Back to top page