zoukankan      html  css  js  c++  java
  • homework-06

    1. 了解Lambda的用法

    计算“Hello World!”中

    a.字母‘e’的个数
    b. 字母‘l’的个数
    nclude <algorithm>
    #include <iostream>
    #include <vector>
    using namespace std;
    
    int main() 
    {
        char *buf = "Hello World!";
       // Create a vector object that contains 10 elements.
       vector<char> 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<iostream>
    #include<string.h>
    #include<stdlib.h>
    using namespace::std;
    
    int main()
    {
        int n;
        char str[]="Hello world!";
        //insert n.
        cin>>n;
        char *p = str + strlen(str) - n;
        cout<<p;
        *p = 0;
        cout<<str<<endl;
        system("pause");
    }

     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、程序的注释

      详见代码

  • 相关阅读:
    linux 命令汇总
    vue搭建环境并创建项目
    CentOS中利用Docker安装RabbitMQ
    CentOS中利用Docker安装Redis
    CentOS双机中Docker下安装Mysql并配置互为主从模式
    CentOS下挂载数据盘
    bootstrap 自适应和响应式布局的区别
    xampp lampp 改变网页root目录的方法
    vue 自适应 Responsive 设计
    vue的二维码生成器
  • 原文地址:https://www.cnblogs.com/jun1022/p/3440526.html
Copyright © 2011-2022 走看看