前田稔(Maeda Minoru)の超初心者のプログラム入門
/*★ Algorithm Step1 前田 稔 ★*/ #include <iostream> #include <vector> using namespace std; void main() { int t[] = { 3, 3, 3, 3, 3, 3, 7, 3, 3, 3 }; vector<int> v(t, t+10); // vector v[]から3でない要素を見つける find_not(v, 3); } |
template<class Container, class T> void find_not(const Container& c, const T& x) { Container::const_iterator first = c.begin(); while(first != c.end() && *first == x) ++first; if (first != c.end()) cout << "見つかった! " << *first << endl; else cout << x << "以外は見つからなかった!" << endl; } |
int t[] = { 3, 3, 3, 3, 7, 3, 3, 5, 3, 3 }; list<int> lst(t,t+10); // list lst[]から3でない要素を見つける find_not(lst, 3); |
int t[] = { 3, 3, 3, 3, 3, 3, 7, 3, 3, 3 }; // int t[]から3でない要素を見つける find_not(t, 3); |