zoukankan      html  css  js  c++  java
  • 数30的小程序

    规则如下: 从1开始,双方轮流, 每次最多数3个数,先数到最后一个数算输

    程序代码:

    /***************************************************
    *
    *
    *
    *
    ****************************************************/
    
    #include <iostream>
    #include <sstream>
    #include <iterator>
    #include <string>
    #include <vector>
    
    bool finish =false;
    
    
    std::vector<int> CalculateNearestWinPoint(int iOri)
    {
        std::vector<int>  VecI;
    
        iOri = iOri -1;
        VecI.push_back(iOri);
    
        while(iOri-4>0)
        {
            iOri = iOri -4 ;
            VecI.push_back(iOri);
        }
        return VecI;
    }
    
    
    void catchNearestWinPoint(std::vector<int> vi,bool finish)
    {
        std::cout<<"the nearest win point is  "<<*(vi.end()-1)<<std::endl;
        vi.pop_back();
        //std::cout<<"user,  pls input you number "<<std::endl;
    
        return;
    }
    
    void calculaterBestReply(std::vector<int>& userInput,std::vector<int>& PointList)
    {
        int iMax= userInput[userInput.size()-1];
    
        //for(std::vector<int>::iterator it = PointList.end(); it != PointList.begin(); --it)
        //{
        //    /* std::cout << *it; ... */
        //    if(*it>iMax)
        //    {
        //        std::cout<<"nearest winpoint is "<<*it<<std::endl;
        //    }
        //}
    
        //for (unsigned i = PointList.size()-1; i-- > 0; )
        for (int i = PointList.size()-1; i >= 0; i-- )
        {
            if(PointList[i]>iMax)
            {
                // mean already find nearest win point 
    
                //std::cout<<"nearest winpoint is "<<PointList[i]<<std::endl;
                
                
                int iMaxTryingTime =0;
                while ((iMax<PointList[i])&&(iMaxTryingTime<3))
                {
                    std::cout<<++iMax<<' ';
                    iMaxTryingTime++;
    
                }
                std::cout<<std::endl;
    
                if(iMax==PointList[0])
                {
                    std::cout<<"robot win!"<<std::endl;
                    finish = true;
                }
                
                return;
            }
        }
        std::cout<<"robot lose!"<<std::endl;
        finish = true;
        return;
    }
    
    void main()
    {
        //std::string s;
    
        //std::getline( std::cin, s );
    
        //std::istringstream is( s );
    
        //std::vector<int> v( ( std::istream_iterator<int>( is ) ), std::istream_iterator<int>() );
    
        //for ( int x : v) std::cout << x << ' ';
        //std::cout << std::endl;
    
        int iPurpose;
        int iInterval;
        int userInput;
        bool FirstReachLose;
        std::string sSingal;
        char c1;
    
        //bool finish =false;
    
        std::cout<<"pls input purpose number	"<<std::endl;
        std::cin>>iPurpose;
    
        std::cout<<"pls input interval counter"<<std::endl;
        std::cin>>iInterval;
        
        std::cout<<"first reach mean l ? (y or n)"<<std::endl;
        std::cin>>c1;
    
    
        if(c1=='y')
            FirstReachLose=true;
        else
            FirstReachLose =false;
    
        std::vector<int> iNearestWinPointList = CalculateNearestWinPoint(iPurpose);
        
        //std::cout<<"The nearest win point of number "<<iPurpose<<" is : "<<std::endl;
        //for(auto i = iNearestWinPointList.begin();i!=iNearestWinPointList.end();++i)
        //        std::cout<<*i<<std::endl;
        while (!finish)
        {
            std::cout<<"pls input one or multi number"<<std::endl;
    
            //std::cin>>userInput;
    
            //FirstReachLose=true;
    
            std::string s;
    
            std::getline( std::cin, s );
    
            std::istringstream is( s );
    
            std::vector<int> v( ( std::istream_iterator<int>( is ) ), std::istream_iterator<int>() );
    
            if (v.size()<=0)
                continue;
            else
            {
    
                calculaterBestReply(v,iNearestWinPointList);
            }
    
            //for ( int x : v) std::cout << x << ' ';
            //std::cout << std::endl;
            //}
        
        }
    
        getchar();
    
        //while(!finish)
        //{
        //    catchNearestWinPoint(iNearestWinPointList,finish);
        //}
    
        
    }

    运行界面:

    先问数多少个数, 然后问每次最多数几个数, 这个只能写3,还不支持其他的数, 再问是不是数到最后一个算输,这里也只能填y

    然后程序正式开始, 数字之间以空格分隔, 回车结束输入 。 

  • 相关阅读:
    s3c2440的2440init.s的分析(转载)
    sql server错误状态列表(转载)
    vector类、迭代器、bitset类(转载)
    VC++以ADO方式连接SQL SERVER
    WinCE流设备驱动简介及GPIO驱动的实现(转载)
    .obj, .lib, .dll, .exe的关系(转载)
    利用DynamicExpression.ParseLambda实现Eval
    Matching Balanced Constructs with .NET Regular Expressions
    VB.NET and C# Comparison【转】
    ReportViewer一个简单例子
  • 原文地址:https://www.cnblogs.com/lthxk-yl/p/8317005.html
Copyright © 2011-2022 走看看