标签:out problem nbsp 输出 pid using cout flag turn
1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍。取完者胜.先取者负输出"Second win".先取者胜输出"First win".
1 #include<iostream> 2 using namespace std; 3 int main() { 4 int n, i,flag=1; 5 int a[1000] = { 0 }; 6 a[0] = 0; a[1] = 1; a[2] = 1; 7 for (i = 3; i < 1000; i++) { 8 a[i] = a[i - 1] + a[i - 2]; 9 } 10 while (cin >> n) { 11 if (n == 0) 12 exit(0); 13 else { 14 for (i = 3; i < 1000; i++) { 15 if (n == a[i]) { 16 cout << "Second win" << endl; 17 flag = 0; 18 break; 19 } 20 } 21 if (flag == 1) { 22 cout << "First win" << endl; 23 } 24 else { 25 flag = 1; 26 } 27 } 28 } 29 return 0; 30 }
标签:out problem nbsp 输出 pid using cout flag turn
原文地址:https://www.cnblogs.com/--HPY-7m/p/11808681.html