zawatins-library

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

View the Project on GitHub zawa-tin/zawatins-library

:heavy_check_mark: makebuc (バケット)
(src/template/makebuc.hpp)

概要

入力で与えた列 $A$ に対して $B_i\ =\ \text{cnt} (i)$ を満たす $B$ を生成して返す。ここで $\text{cnt}(i)$ とは $A_j\ =\ i$ を満たす $j$ の数とする。

機能

関数

std::vector<int> zawa::makebuc<T>(const std::vector<T>& A, const T& sup)

std::vector<int> zawa::makebuc(const std::string& S, bool lower = true)

改修案?

Verified with

Code

#pragma once

#include <vector>
#include <string>

namespace zawa {

template <class T>
std::vector<int> makebuc(const std::vector<T>& A, const T& sup) {
	std::vector<int> res(sup, 0);
	for (const auto& a : A) {
		res[a]++;
	}
	return res;
}

std::vector<int> makebuc(const std::string& S, bool lower = true) {
	std::vector<int> res(26, 0);
	int minus = (lower ? (int)'a' : (int)'A');
	for (const auto& c : S) {
		res[c - minus]++;
	}
	return res;
}

} // namespace zawa
#line 2 "src/template/makebuc.hpp"

#include <vector>
#include <string>

namespace zawa {

template <class T>
std::vector<int> makebuc(const std::vector<T>& A, const T& sup) {
	std::vector<int> res(sup, 0);
	for (const auto& a : A) {
		res[a]++;
	}
	return res;
}

std::vector<int> makebuc(const std::string& S, bool lower = true) {
	std::vector<int> res(26, 0);
	int minus = (lower ? (int)'a' : (int)'A');
	for (const auto& c : S) {
		res[c - minus]++;
	}
	return res;
}

} // namespace zawa
Back to top page