ã©ã¯ã« vector ãä½ã
ãããã Google Code Jam ã§ãã Google Code Jam ã¯å
¥åã¨ãã vector
#include <vector> #include <iostream> #include <algorithm> #include <iterator> #include <assert.h> using namespace std; template <class T> struct vector_ : public vector<T> { vector_() {} template <class U> vector_(vector<U> v) { copy(v.begin(), v.end(), back_inserter(*this)); } template <class U> operator vector<U>() { vector<U> r; copy(this->begin(), this->end(), back_inserter(r)); return r; } }; struct any_null_vector { template <class T> vector_<T> operator << (T t) { vector_<T> r; r.push_back(t); return r; } template <class T> operator vector_<T>() { vector_<T> r; return r; } }; template <class T> vector_<T> operator << (vector_<T> v, T t) { v.push_back(t); return v; } template <class T> ostream& operator << (ostream& os, const vector<T>& v) { os << '['; for (int i = 0; i < v.size(); i++) { if (i) os << ", "; os << v[i]; } os << ']'; return os; } any_null_vector vec; int main() { vector<int> iv = vec << 1 << 2 << 3; cout << iv << endl; vector<string> sv = vec << "hage" << "hige"; cout << sv << endl; vector<vector<string> > ssv = vec << (vec << "boke" << "bake") << (vec << "hage" << "hige"); cout << ssv << endl; }
ãããããªç©ä½ãæä¾ãã¦æµãæ½°ãè¨ç»â¦ã¨ãã§ã¯ãã¶ãç¡ãã¨æãã¾ããã¨ããããªããä»ã¨ã¦ãããæ°ãªãæãªã®ã§ãåé¡æ¬¡ç¬¬ã§ããã Python ã§åå ãããããªã¼ã¨æã£ã¦ã¾ããã¾ã ã¿ããªã® Python èªã¿çµãã£ã¨ããã®ãåé¡ã§ãã