cp-library

競技プログラミング用 C++ ライブラリ

View the Project on GitHub qandori/cp-library

:heavy_check_mark: test/trie.test.cpp

test/trie.test.cpp · GitHub で見る

検証問題

依存ライブラリ

コード

#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C"
#include "string/trie.hpp"
#include "components/fast_io.hpp"

int main() {
	FastInput input;
	FastOutput output;
	int n = 0;
	input.read(n);
	Trie<26, 'A'> trie;
	for (int i = 0; i < n; ++i) {
		std::string command, word;
		input.read(command), input.read(word);
		if (command == "insert") {
			if (!trie.contains(word)) trie.insert(word);
		} else output.println(trie.contains(word) ? "yes" : "no");
	}
}
Back to top page