#include #include #include template class avector { protected: T * data; int size, capacity; public: avector(); ~avector(); int getsize(); void push_back(T s); T & operator[](int i); void enlarge_to(int newcap); }; template avector::avector() { size = 0; capacity = 0; data = NULL; } template avector::~avector() { delete [] data; size = 0; capacity = 0; } template int avector::getsize() { return size; } template void avector::push_back(T s) { if (size >= capacity) enlarge_to(size + 1); data[size] = s; size += 1; } template T & avector::operator[](int i) { assert(i >= 0); if (i >= capacity) enlarge_to(i + 1); return data[i]; } template void avector::enlarge_to(int newcap) { if (newcap <= capacity) return; T * d = new string[newcap]; for (int i = 0; i < size; i += 1) d[i] = data[i]; delete [] data; data = d; capacity = newcap; } int main() { avector A; string s; while (true) { cin >> s; if (s == "end") break; A.push_back(s); } for (int i = 0; i < A.getsize(); i += 1) cout << i << ": " << A[i] << "\n"; }