// 31_31-3.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <vector>
#include <algorithm>

using namespace std;

void disp_i(int *d, int n)
{
	for (int i = 0; i < n; i++) {
		cout << *d++ << " ";
	}
	cout << '\n';
}

void disp_v(vector<int> &obj)
{
	vector<int>::iterator p;
	for (p = obj.begin(); p != obj.end(); p++) {
		cout << *p << " ";
	}
	cout << '\n';
}

bool greatequ40(int n)
{
	return n >= 40;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int n, *ip;
	int dt[7] = { 10, 20, 33, 40, 50, 33, 60 };
	vector<int> vt(dt, dt+7);
	vector<int>::iterator vp;

	cout << "-----内容を見る\n";
	cout << "dt: ";
	disp_i(dt, 7);
	cout << "vt: ";
	disp_v(vt);

	cout << "-----33の個数を表示(count)\n";
	n = count(dt, dt+7, 33);
	cout << "dt: " << n << '\n';
	n = count(vt.begin(), vt.end(), 33);
	cout << "vt: " << n << '\n';

	cout << "-----40以上の個数を表示(count_if)\n";
	n = count_if(dt, dt+7, greatequ40);
	cout << "dt: " << n << '\n';
	n = count_if(vt.begin(), vt.end(), greatequ40);
	cout << "vt: " << n << '\n';

	cout << "-----33をfindしそこから後ろを表示\n";
	cout << "dt: ";
	ip = find(dt, dt+7, 33);
	for (; ip != dt+7; ip++) { cout << *ip << " "; }
	cout << '\n';
	cout << "vt: ";
	vp = find(vt.begin(), vt.end(), 33);
	for (; vp != vt.end(); vp++) { cout << *vp << " "; }
	cout << '\n';

	cout << "-----40以上をfind_ifしそこから後ろを表示\n";
	cout << "dt: ";
	ip = find_if(dt, dt+7, greatequ40);
	for (; ip != dt+7; ip++) { cout << *ip << " "; }
	cout << '\n';
	cout << "vt: ";
	vp = find_if(vt.begin(), vt.end(), greatequ40);
	for (; vp != vt.end(); vp++) { cout << *vp << " "; }
	cout << '\n';





	MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);

	return 0;
}

