1. 了解Lambda的用法
计算“Hello World!”中
a.字母‘e’的个数
b. 字母‘l’的个数
nclude#include #include using namespace std;int main() { char *buf = "Hello World!"; // Create a vector object that contains 10 elements. vector v; for (int i = 0; i < strlen(buf); ++i) { v.push_back(buf[i]); } // Count the number of even numbers in the vector by // using the for_each function and a lambda. int eCount = 0; int lCount =0 ; for_each(v.begin(), v.end(), [&eCount,&lCount] (char ch) { if (ch == 'e') { eCount++; } else if (ch == 'l') { lCount++; } }); // Print the count of even numbers to the console. cout << "There are " << eCount << " e in the vector." << endl; cout << "There are " << lCount << " l in the vector." << endl; system("pause");}
2. 练习使用智能指针
打印“Hello World!”循环右移n位的结果
Example:
n = 1, output = “!Hello World”
n = 3, output = “ld!Hello Wor”
#include#include #include using namespace::std;int main(){ int n; char str[]="Hello world!"; //insert n. cin>>n; char *p = str + strlen(str) - n; cout<
3.围棋游戏
1、playPrev
返回则先要将本棋子移除,返回到上一个棋子的内容,并且判断当前子去掉之前是否有使对方子被吃掉的现象,如果有,获取数据并恢复,最后遍历棋盘更新。
public void playPrev(GoMove gm) { int i = gm.Point.X; int j = gm.Point.Y; Grid[i,j].removeStone(); m_gmLastMove = gameTree.peekPrev(); if (m_gmLastMove != null) Grid[m_gmLastMove.Point.X,m_gmLastMove.Point.Y].setUpdated(); if (gm.DeadGroup != null) { System.Collections.IEnumerator myEnumerator = gm.DeadGroup.GetEnumerator(); while (myEnumerator.MoveNext()) { Point p; p = (Point)myEnumerator.Current; Grid[p.X,p.Y].setNoKilled(); Grid[p.X,p.Y].setStone(nextTurn(gm.Color)); } } optRepaint(); return; }
2、点评一下这个程序设计方面的不足
本人水平较渣,除了错误处理基本没有外还真没看出什么缺点·····
3、程序的注释
详见代码