C++クラシックプログラミングテーマ(九)マッチ棒ゲームをする

5333 ワード

        ,         ,    。            
     ,            ,        。        ,
        ,           16   。            
     ?        。
#include
using namespace std;

/*
1   2    3    4
16  16  16   16  :now
8   8    8   40  :4 lose
4   4   36   20  :3 lose
2   34  18   10  :2 lose
32  17   9    5  :1 lose


1/2 Backstepping
*/

int main()
{
	int a[4] = {16,16,16,16};

	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			if (j!=i)
			{
				a[j] = a[j] / 2;
				a[i] = a[i] + a[j];
			}
		}
	}

	cout << "In the begining:" << endl;
	for (int i = 0; i < 4; i++)
	{
		cout << (char)(65 + i) << " has " << a[i] <<
			" matches, and lost at round " << 4 - i << endl;
	}


	system("pause");
	return 0;
}