• C++学习记录(留坑)


    #include <iostream>
    #include <ctime>
    #include <fstream>    ///文件打开有o.i权限 
    #include <stdio.h>
    #include <sstream>   ////bool转string 
    #include <stdlib.h>
    #include <string>
    using namespace std;
    char filename[]="game.log";
    string times(){
        time_t now =time(0);    ///时间戳 
        char* dd=ctime(&now);    ///格式化 
        return dd;
    }
    void gamefile(string log){
        ofstream outfile;
        outfile.open(filename);
        outfile<<log<<endl;
        outfile.close();
    }
    bool game(){
        int list[6]={1,2,3,4,5,6};
        srand(time(0));
        int nub=rand()%6+1;
        cout<<"input a nubmer:";
        int guess;
        cin>>guess;
        int real=list[nub];
        int gu=list[guess];
        if(gu==real){
            cout<<"!!!!!TTTTTTTTT";
            return true; 
        }
        else{
            cout<<"F,try again!!!";
            return false;
        }
    }
    char* strandchar(string strings){
        char o[]="";
        int i;
        for (i=0;i<strings.length();i++){
            o[i]=strings[i];
        }
        return o;
        
    } 
    int main(){
    //    string dd="fafdsdfsd";
    //    char* aa=strandchar(dd);
        int i=1; 
    //    char* logg;
        while(1){
            bool jg=game();
            ostringstream os1;      ///类型转换 
            os1<<jg;
            string logtime=times();
            logtime=strandchar(logtime); 
    //        cout<<logtime<<endl; 
    //        logg.append(strandchar(logtime));
            char cc=static_cast<char>(i);
    //        string logg=("%d
    第%di轮结果:%d",logtime,i,string(os1.str()));
            char* tp=("轮数:");
    //        cout<<tp<<endl; 
    //        string logg;
    //        logg.append(logtime);
    //        logg.append(tp);
    //        logg.append(cc);
    //        char* logg=logtime+logg;
    //        sprintf(logg,"%s,%s",logtime,tp);
            stringstream logg;
            logg<<logtime<<tp<<cc;
    //        string loggg=logg.str();
            cout<<logg<<endl;
            gamefile(logg);
            if (true==jg){
    //            gamefile(loggg);
    //            cout<<loggg<<endl;
                break;
            }
            i++;    
        }
        
    }
    
    /////时间and文件 
    //int main()
    //{
    //    time_t now =time(0);
    //    char* dd=ctime(&now); 
    //    ofstream outfile;
    //    outfile.open("cxxtest.txt");
    //    outfile<<dd<<endl;
    //    cout<<dd<<endl;
    //}
    
    //extern int a , b,c;     #全局定义 
    ///////9*9乘法 
    //int main()
    //{
    //    cout << "Hello, world!" << endl;
    //
    ////    time_t now = time(0);
    ////    char* c=ctime(&now);
    //
    //    for (int i=1;i<=9;i++){
    //        for (int j=1;j<=i;j++){
    //            printf("%d*%d=%d  ",i,j,i*j);
    //        }
    //        printf("
    ");
    //    }
    //
    ////    cout << c ;
    //    return 0;
    //}
    /////数组操作 
    //int main(){
    //    int list[10]={0,1,2,3,4,5,6,7,8,9};
    //    
    //    int a=list[i];
    ////    printf(a);
    //    cout<<a;
    //    return 0;
    //}
    //    
  • 相关阅读:
    总结第一、二类斯特林数(模板)
    总结组合数的几种求法(模板)
    HDU5521 Meeting(dijkstra+巧妙建图)
    BZOJ4152 The Captain(dijkstra+巧妙建图)
    CF1194D 1-2-K Game (博弈论)
    JavaScript字符串的操作
    JavaScript基础–闭包
    JavsScript基础–声明提升
    JavaScript基础–作用域
    css基础(一)
  • 原文地址:https://www.cnblogs.com/MrRead/p/9121420.html
Copyright © 2020-2023  润新知