Skip to content

Instantly share code, notes, and snippets.

@takoeight0821 takoeight0821/main.cc
Last active Dec 11, 2018

Embed
What would you like to do?
競プロの簡単な問題を解いたときの副産物
#include <iostream>
#include <tuple>
#include <algorithm>
#include <vector>
using namespace std;
template <typename T>
unsigned int digit_sum(T x, unsigned int base) {
auto result = 0;
while (x > 0) {
result += x % base;
x /= base;
}
return result;
}
template <typename T>
unsigned int digit_sum(T x) {
return digit_sum(x, 10);
}
template <typename Container>
void read_sequence(Container& con, typename Container::size_type n) {
read_sequence(con, n,
[]() {
typename Container::value_type tmp;
cin >> tmp;
return tmp;
});
}
template <typename Container, typename ReadFunc>
void read_sequence(Container& con, typename Container::size_type n, ReadFunc f) {
for (typename Container::size_type i = 0; i < n; i++) {
con.push_back(f());
}
}
template <typename Container>
void erase_adjacent_dup(Container& con) {
con.erase(unique(con.begin(), con.end()),
con.end());
}
int main(void) {
cout << digit_sum(1011) << endl;
vector<int> vec;
read_sequence(vec, 10);
sort(vec.begin(), vec.end());
erase_adjacent_dup(vec);
vector<tuple<int, int, int>> txy;
read_sequence(txy, 10,
[]() {
int t, x, y;
cin >> t >> x >> y;
return make_tuple(t, x, y);
});
}
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.