library

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

View the Project on GitHub yuruhi/library

:heavy_check_mark: test/RunLengthEncoding.test.cpp

Depends on

Code

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Final/0506"
#include "./../Utility/RunLengthEncoding.cpp"
#include <iostream>
#include <string>
using namespace std;

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);

	while (true) {
		int n;
		cin >> n;
		if (n == 0) break;
		string s;
		cin >> s;
		for (int i = 0; i < n; ++i) {
			string t;
			for (auto [count, value] : RunLengthEncoding(s)) {
				t += to_string(count);
				t += value;
			}
			s = t;
		}
		cout << s << endl;
	}
}
#line 1 "test/RunLengthEncoding.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Final/0506"
#line 2 "Utility/RunLengthEncoding.cpp"
#include <vector>
#include <iterator>
#include <utility>

template <class InputIterator, class value_type = typename InputIterator::value_type>
auto RunLengthEncoding(InputIterator first, InputIterator last) {
	std::vector<std::pair<std::size_t, value_type>> result;
	for (; first != last; ++first) {
		if (result.empty() || result.back().second != *first) {
			result.emplace_back(1, *first);
		} else {
			result.back().first++;
		}
	}
	return result;
}

template <class Container> auto RunLengthEncoding(const Container& a) {
	return RunLengthEncoding(a.begin(), a.end());
}

template <class InputIterator, class value_type = typename InputIterator::value_type>
auto RunLengthEncoding_pair(InputIterator first, InputIterator last) {
	std::vector<std::size_t> count;
	std::vector<value_type> value;
	for (; first != last; ++first) {
		if (value.empty() || value.back() != *first) {
			count.push_back(1);
			value.push_back(*first);
		} else {
			count.back()++;
		}
	}
	return std::pair(count, value);
}

template <class Container> auto RunLengthEncoding_pair(const Container& a) {
	return RunLengthEncoding_pair(a.begin(), a.end());
}
#line 3 "test/RunLengthEncoding.test.cpp"
#include <iostream>
#include <string>
using namespace std;

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);

	while (true) {
		int n;
		cin >> n;
		if (n == 0) break;
		string s;
		cin >> s;
		for (int i = 0; i < n; ++i) {
			string t;
			for (auto [count, value] : RunLengthEncoding(s)) {
				t += to_string(count);
				t += value;
			}
			s = t;
		}
		cout << s << endl;
	}
}
Back to top page