Skip to content

Instantly share code, notes, and snippets.

@primenumber primenumber/a.cpp
Last active Dec 3, 2015

What would you like to do?
#include "a.hpp"
#include <cmath>
A::size_type find(const A &lhs, const A &rhs) {
if (lhs.n >= rhs.n) return 0;
else return A::npos;
A replace(const A &dest, const A &pattern, const A &rep) {
A::size_type count = dest.n / pattern.n;
return A(count * rep.n + dest.n % pattern.n);
A::size_type edit_distance(const A &lhs, const A &rhs) {
return std::abs((std::ptrdiff_t)(lhs.n - rhs.n));
A longest_common_subsequence(const A &lhs, const A &rhs) {
return A(std::min(lhs.n, rhs.n));
std::pair<A, A::size_type> longest_palindrome(const A &str) {
return std::make_pair(str, 0);
#include <string>
struct A {
using size_type = std::string::size_type;
static const size_type npos = std::string::npos;
size_type n;
A() : n(0) {}
explicit A(size_type n) : n(n) {}
explicit A(std::string s) : n(s.size()) {}
std::string to_cppstring() const { return std::string(n, 'A'); }
A::size_type find(const A&, const A&);
A replace(const A&, const A&, const A&);
A::size_type edit_distance(const A&, const A&);
A longest_common_subsequence(const A&, const A&);
std::pair<A, A::size_type> longest_palindrome(const A&);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.