---
# System prepended metadata

title: Read_file

---

# Read_file

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<vector>
#include <sstream>
#include <fstream>
#include <algorithm>
using namespace std;
vector<string> rs;
#define side_ str=="1w"||str=="2w"||str=="8w"||str=="9w"||str=="1t"||str=="2t"||str=="8t"||str=="9t"||str=="1s"||str=="2s"||str=="8s"||str=="9s"
#define not_side str!="1w"||str!="2w"||str!="8w"||str!="9w"||str!="1t"||str!="2t"||str!="8t"||str!="9t"||str!="1s"||str!="2s"||str!="8s"||str!="9s"
#define character str=="東"||str=="南"||str=="西"||str=="北"||str=="中"||str=="發"||str=="白"
#define split "----------------------------------------------"
    vector<int> player1,player2,player3,player4;
    vector<int> my_card;
    vector<int> eat1,eat2,eat3,eat4;
    vector<int> pong1,pong2,pong3,pong4;
    vector<int> gong1,gong2,gong3,gong4;
    int mo_cnt1,mo_cnt2,mo_cnt3,mo_cnt4;
    int add_gong_cnt1,add_gong_cnt2,add_gong_cnt3,add_gong_cnt4;
    int gong_cnt1,gong_cnt2,gong_cnt3,gong_cnt4;
    int had_round=0,winner=0;
    int win_sum_0=0,win_sum_1=0,win_sum_2=0,win_sum_3=0,win_sum_4=0,win_sum_5=0;
    int step[21];


    vector<string>act1,act2,act3,act4;
    vector<string>w,t,s,ch;
    vector<string>side_w,side_t,side_s;

    string suit[4]={"w","t","s",""};
    string num[9]={"1","2","3","4","5","6","7","8","9"};
    string word[7]={"東","南","西","北","中","發","白"};

 void read_write(){
    fstream read_file;
    string link="";
    char buffer[80];
    for(int i=1;i<=24;i++){//M
        string str="TCGA2016_M";
        str=str+to_string(i)+"_";
        link=str;
        for(int j=1;j<=16;j++){//num of data in M1~M24(or 16)
            str=link+to_string(j)+".log";
            read_file.open(str);
            while(!read_file.eof()){
                read_file.getline(buffer,80,'\n');
                string tmp=buffer;
                rs.push_back(tmp);

            }
            read_file.close();
            rs.push_back(split);
        }
    }
 }

/*void read_write()
{
    FILE *fp = NULL;
   // FILE *fq = NULL;
    char filename_body[100];
    for(int i = 1; i <= 16; i ++)
    {
        char filename[16] ="ICGA2016_M2_";
        memset(filename_body, 0, sizeof(filename_body));
        itoa(i, filename_body, 10);
        strcat(filename,filename_body);
        char filename_tail[5] = ".log";
        strcat(filename,filename_tail);

        if((fp=fopen(filename, "r")) == NULL)
        {
            cout<<"open filename fail..."<<endl;
        }

        char str[20];
        while(fscanf(fp, "%[^\n]%*c", str) ==1)
        {

            string tmp = str;
            rs.push_back(tmp);
            //cout<<tmp<<endl;
        }
        rs.push_back(split);


        fclose(fp);

    }
}*/

void print_mo_cnt(){
    cout<<"player1's total mo count:"<<mo_cnt1<<endl;
    cout<<"player2's total mo count:"<<mo_cnt2<<endl;
    cout<<"player3's total mo count:"<<mo_cnt3<<endl;
    cout<<"player4's total mo count:"<<mo_cnt4<<endl;


}
void print_sum(){

     cout<<endl;
     cout<<"player1's eat count:"<<eat1.size()/3<<endl;
     cout<<"player2's eat count:"<<eat2.size()/3<<endl;
     cout<<"player3's eat count:"<<eat3.size()/3<<endl;
     cout<<"player4's eat count:"<<eat4.size()/3<<endl;

     cout<<endl;

     cout<<"player1's pong count:"<<pong1.size()/3-add_gong_cnt1<<endl;
     cout<<"player2's pong count:"<<pong2.size()/3-add_gong_cnt2<<endl;
     cout<<"player3's pong count:"<<pong3.size()/3-add_gong_cnt3<<endl;
     cout<<"player4's pong count:"<<pong4.size()/3-add_gong_cnt4<<endl;

     cout<<endl;
     cout<<"player1's gong count:"<<gong_cnt1<<endl;
     cout<<"player2's gong count:"<<gong_cnt2<<endl;
     cout<<"player3's gong count:"<<gong_cnt3<<endl;
     cout<<"player4's gong count:"<<gong_cnt4<<endl;

     cout<<endl;
     int sum_of_player1=eat1.size()/3+pong1.size()/3-add_gong_cnt1+gong_cnt1;
     int sum_of_player2=eat2.size()/3+pong2.size()/3-add_gong_cnt2+gong_cnt2;
     int sum_of_player3=eat3.size()/3+pong3.size()/3-add_gong_cnt3+gong_cnt3;
     int sum_of_player4=eat4.size()/3+pong4.size()/3-add_gong_cnt4+gong_cnt4;
     cout<<"player1's eat+pong+gong count:"<<sum_of_player1<<endl;
     cout<<"player2's eat+pong+gong count:"<<sum_of_player2<<endl;
     cout<<"player3's eat+pong+gong count:"<<sum_of_player3<<endl;
     cout<<"player4's eat+pong+gong count:"<<sum_of_player4<<endl;
     if(winner==1){
        if(sum_of_player1==0)
            win_sum_0++;
        else if(sum_of_player1==1)
            win_sum_1++;

        else if(sum_of_player1==2)
            win_sum_2++;

        else if(sum_of_player1==3)
            win_sum_3++;

        else if(sum_of_player1==4)
            win_sum_4++;

        else if(sum_of_player1==5)
            win_sum_5++;

     }
     else if(winner==2){
        if(sum_of_player2==0)
            win_sum_0++;
        else if(sum_of_player2==1)
            win_sum_1++;

        else if(sum_of_player2==2)
            win_sum_2++;

        else if(sum_of_player2==3)
            win_sum_3++;

        else if(sum_of_player2==4)
            win_sum_4++;

        else if(sum_of_player2==5)
            win_sum_5++;

     }
    else if(winner==3){
        if(sum_of_player3==0)
            win_sum_0++;
        else if(sum_of_player3==1)
            win_sum_1++;

        else if(sum_of_player3==2)
            win_sum_2++;

        else if(sum_of_player3==3)
            win_sum_3++;

        else if(sum_of_player3==4)
            win_sum_4++;

        else if(sum_of_player3==5)
            win_sum_5++;

     }
     else if(winner==4){
        if(sum_of_player4==0)
            win_sum_0++;
        else if(sum_of_player4==1)
            win_sum_1++;

        else if(sum_of_player4==2)
            win_sum_2++;

        else if(sum_of_player4==3)
            win_sum_3++;

        else if(sum_of_player4==4)
            win_sum_4++;

        else if(sum_of_player4==5)
            win_sum_5++;

     }

}

void sort_(){
        sort(w.begin(),w.end());
            for(int i=0;i<w.size();i++)
                cout<<w[i];

                if(w.empty()){}
                else if(!w.empty()&&(!t.empty()||!s.empty()||!ch.empty()))
                cout<<"w,";
                else if(!w.empty()&&t.empty()&&s.empty()&&ch.empty())
                cout<<"w";

        sort(t.begin(),t.end());
            for(int i=0;i<t.size();i++)
                cout<<t[i];
                if(t.empty()){}
                else if(!t.empty()&&(!s.empty()||!ch.empty()))
                cout<<"t,";
                else if(!t.empty()&&s.empty()&&ch.empty())
                cout<<"t"<<endl;

        sort(s.begin(),s.end());
            for(int i=0;i<s.size();i++)
                cout<<s[i];
                if(s.empty()){}
                else if(!s.empty()&&!ch.empty())
                cout<<"s,";
                else if(!s.empty()&&ch.empty())
                cout<<"s";

        sort(ch.begin(),ch.end());
                for(int i=0;i<ch.size();i++)
                      cout<<ch[i];
}
void clear_(){
        w.clear();
        t.clear();
        s.clear();
        ch.clear();
}
void clear_for_everything(){
        eat1.clear();eat2.clear();eat3.clear();eat4.clear();
        pong1.clear(); pong2.clear(); pong3.clear(); pong4.clear();
        gong1.clear(); gong2.clear(); gong3.clear(); gong4.clear();
        player1.clear(); player2.clear(); player3.clear(); player4.clear();
        act1.clear(); act2.clear(); act3.clear(); act4.clear();
        mo_cnt1=mo_cnt2=mo_cnt3=mo_cnt4=0;
        add_gong_cnt1=add_gong_cnt2=add_gong_cnt3=add_gong_cnt4=0;
        gong_cnt1=gong_cnt2=gong_cnt3=gong_cnt4=0;

}
void side_clear(){
    side_w.clear();
    side_t.clear();
    side_s.clear();
}
string tile_(int n){
        string sui,numb,tile;
        int r,temp;
        bool is_word=false,is_w=false,is_t=false,is_s=false;
        if(n/100==1){
           sui=suit[0];
           is_w=true;
        }
        if(n/100==2){
           sui=suit[1];
           is_t=true;
        }
        if(n/100==3){
           sui=suit[2];
           is_s=true;
        }
        if(n/100==4){
           sui=suit[3];
           is_word=true;
        }

        r=n%100;
        temp=r/10;
        if(is_word){
            numb=word[temp-1];
            ch.push_back(numb);
        }
        else
            numb=num[temp-1];

        if(is_w)
            w.push_back(numb);

        else if(is_t)
            t.push_back(numb);

        else if(is_s)
            s.push_back(numb);

        tile=numb+sui;
        return tile;

}
void print_every(){
    vector<string>side;
    string str;
    cout<<endl;
    cout<<"player1 throw:"<<endl;
    cout<<"依序為:";
    for(int i=0;i<player1.size();i++){  //cout<<player1[i]<<" ";
        cout<<tile_(player1[i])<<" ";
        str=tile_(player1[i]);

        if(side_)
            side.push_back(str);

        else if(not_side){
            if(character){}


            else{
                step[i+1]++;

            }

        }
    }//for
    cout<<endl;

    cout<<"整理後:";
        clear_();
    for(int i=0;i<player1.size();i++)
        tile_(player1[i]);
        sort_();

    cout<<endl;

    cout<<"邊張牌統計:";
    for(int i=0;i<side.size();i++){
        cout<<side[i]<<" ";
        string temps,buffer_0,buffer_1;
        temps=side[i];
        buffer_1=temps[1];
        if(buffer_1=="w"){
            buffer_0=temps[0];
            side_w.push_back(buffer_0);
        }
        if(buffer_1=="t"){
            buffer_0=temps[0];
            side_t.push_back(buffer_0);
        }
        if(buffer_1=="s"){
            buffer_0=temps[0];
            side_s.push_back(buffer_0);
        }

    }
    cout<<endl;
    cout<<"統整後:"<<endl;
    if(!side_w.empty()){
        sort(side_w.begin(),side_w.end());
        for(int i=0;i<side_w.size();i++)
            cout<<side_w[i];

        cout<<"w"<<endl;

    }
    if(!side_t.empty()){
        sort(side_t.begin(),side_t.end());
        for(int i=0;i<side_t.size();i++)
            cout<<side_t[i];

        cout<<"t"<<endl;
    }
    if(!side_s.empty()){
        sort(side_s.begin(),side_s.end());
        for(int i=0;i<side_s.size();i++)
            cout<<side_s[i];
        cout<<"s"<<endl;
    }

    side.clear();
    side_clear();
    cout<<endl;
        //---------------------------
    cout<<"player2 throw:"<<endl;
    cout<<"依序為:";
    for(int i=0;i<player2.size();i++){  //cout<<player2[i]<<" ";
        cout<<tile_(player2[i])<<" ";
        str=tile_(player2[i]);
        if(side_)
            side.push_back(str);
        else if(not_side){
            if(character){}


            else{
                step[i+1]++;

            }

        }
    }
    cout<<endl;

    cout<<"整理後:";
    clear_();



    for(int i=0;i<player2.size();i++)
        tile_(player2[i]);
    sort_();
    cout<<endl;
    cout<<"邊張牌統計:";
    for(int i=0;i<side.size();i++){
        cout<<side[i]<<" ";
        string temps,buffer_0,buffer_1;
        temps=side[i];
        buffer_1=temps[1];
        if(buffer_1=="w"){
            buffer_0=temps[0];
            side_w.push_back(buffer_0);
        }
        if(buffer_1=="t"){
            buffer_0=temps[0];
            side_t.push_back(buffer_0);
        }
        if(buffer_1=="s"){
            buffer_0=temps[0];
            side_s.push_back(buffer_0);
        }

    }
        cout<<endl;
        cout<<"統整後:"<<endl;
    if(!side_w.empty()){
        sort(side_w.begin(),side_w.end());
        for(int i=0;i<side_w.size();i++)
            cout<<side_w[i];

        cout<<"w"<<endl;

    }
    if(!side_t.empty()){
        sort(side_t.begin(),side_t.end());
        for(int i=0;i<side_t.size();i++)
            cout<<side_t[i];

        cout<<"t"<<endl;
    }
    if(!side_s.empty()){
        sort(side_s.begin(),side_s.end());
        for(int i=0;i<side_s.size();i++)
            cout<<side_s[i];
        cout<<"s"<<endl;
    }
    side.clear();
    side_clear();
    cout<<endl;
        //---------------------------
    cout<<"player3 throw:"<<endl;
    cout<<"依序為:";
    for(int i=0;i<player3.size();i++){   //cout<<player3[i]<<" ";
        cout<<tile_(player3[i])<<" ";
        str=tile_(player3[i]);
        if(side_)
            side.push_back(str);

        else if(not_side){
            if(character){}


            else{
                step[i+1]++;

            }

        }
    }
    cout<<endl;

    cout<<"整理後:";
        clear_();
    for(int i=0;i<player3.size();i++)
        tile_(player3[i]);
    sort_();
    cout<<endl;
    cout<<"邊張牌統計:";
    for(int i=0;i<side.size();i++){
        cout<<side[i]<<" ";
        string temps,buffer_0,buffer_1;
        temps=side[i];
        buffer_1=temps[1];
        if(buffer_1=="w"){
            buffer_0=temps[0];
            side_w.push_back(buffer_0);
        }
        if(buffer_1=="t"){
            buffer_0=temps[0];
            side_t.push_back(buffer_0);
        }
        if(buffer_1=="s"){
            buffer_0=temps[0];
            side_s.push_back(buffer_0);
        }
    }
    cout<<endl;
    cout<<"統整後:"<<endl;
    if(!side_w.empty()){
        sort(side_w.begin(),side_w.end());
        for(int i=0;i<side_w.size();i++)
            cout<<side_w[i];

        cout<<"w"<<endl;

    }
    if(!side_t.empty()){
        sort(side_t.begin(),side_t.end());
        for(int i=0;i<side_t.size();i++)
            cout<<side_t[i];

        cout<<"t"<<endl;
    }
    if(!side_s.empty()){
        sort(side_s.begin(),side_s.end());
        for(int i=0;i<side_s.size();i++)
            cout<<side_s[i];
        cout<<"s"<<endl;
    }
    side.clear();
    side_clear();
    cout<<endl;

        //---------------------------
    cout<<"player4 throw:"<<endl;
    cout<<"依序為:";
    for(int i=0;i<player4.size();i++){   //cout<<player4[i]<<" ";
        cout<<tile_(player4[i])<<" ";
    str=tile_(player4[i]);
        if(side_)
            side.push_back(str);

        else if(not_side){
            if(character){}


            else{
                step[i+1]++;

            }

        }

    }
    cout<<endl;
    cout<<"整理後:";
        clear_();
    for(int i=0;i<player4.size();i++)
        tile_(player4[i]);
    sort_();
    cout<<endl;
    cout<<"邊張牌統計:";
    for(int i=0;i<side.size();i++){
        cout<<side[i]<<" ";
        string temps,buffer_0,buffer_1;
        temps=side[i];
        buffer_1=temps[1];
        if(buffer_1=="w"){
            buffer_0=temps[0];
            side_w.push_back(buffer_0);
        }
        if(buffer_1=="t"){
            buffer_0=temps[0];
            side_t.push_back(buffer_0);
        }
        if(buffer_1=="s"){
            buffer_0=temps[0];
            side_s.push_back(buffer_0);
        }


    }
        cout<<endl;
        cout<<"統整後:"<<endl;
    if(!side_w.empty()){
        sort(side_w.begin(),side_w.end());
        for(int i=0;i<side_w.size();i++)
            cout<<side_w[i];

        cout<<"w"<<endl;

    }
    if(!side_t.empty()){
        sort(side_t.begin(),side_t.end());
        for(int i=0;i<side_t.size();i++)
            cout<<side_t[i];

        cout<<"t"<<endl;
    }
    if(!side_s.empty()){
        sort(side_s.begin(),side_s.end());
        for(int i=0;i<side_s.size();i++)
            cout<<side_s[i];
        cout<<"s"<<endl;
    }
    side.clear();
    side_clear();
    cout<<endl;
//---------------------------------------------------------------------------
    cout<<"my card(final):"<<endl;
        clear_();
    for(int i=0;i<my_card.size();i++)
        tile_(my_card[i]);

        sort(w.begin(),w.end());
            for(int i=0;i<w.size();i++)
                cout<<w[i];
                cout<<"w,";

        sort(t.begin(),t.end());
            for(int i=0;i<t.size();i++)
                cout<<t[i];

                cout<<"t,";

        sort(s.begin(),s.end());
            for(int i=0;i<s.size();i++)
                cout<<s[i];

                if(!ch.empty())
                cout<<"s,";
                else
                cout<<"s";

        sort(ch.begin(),ch.end());
                for(int i=0;i<ch.size();i++)
                      cout<<ch[i];

    cout<<endl;

//---------------------------------------------------------------------------

    cout<<endl;
    cout<<"player1 eat card:"<<endl;
       clear_();
    for(int i=0;i<eat1.size();i++)   //cout<<eat1[i]<<" ";
       cout<< tile_(eat1[i])<<" ";
       cout<<endl;
       cout<<"整理後:";
       sort_();
      cout<<endl;
    cout<<endl;
    cout<<"player2 eat card:"<<endl;
    clear_();
    for(int i=0;i<eat2.size();i++)   //cout<<eat2[i]<<" ";
        cout<<tile_(eat2[i])<<" ";
        cout<<endl;
        cout<<"整理後:";
        sort_();
    cout<<endl;
    cout<<endl;
    cout<<"player3 eat card:"<<endl;
    clear_();
    for(int i=0;i<eat3.size();i++)   //cout<<eat3[i]<<" ";
        cout<<tile_(eat3[i])<<" ";
        cout<<endl;
        cout<<"整理後:";
        sort_();
    cout<<endl;
    cout<<endl;
    cout<<"player4 eat card:"<<endl;
    clear_();
    for(int i=0;i<eat4.size();i++)   //cout<<eat4[i]<<" ";
        cout<<tile_(eat4[i])<<" ";
        cout<<endl;
        cout<<"整理後:";
        sort_();
    cout<<endl;
//------------------------------------------------------------------------------
    cout<<endl;
    cout<<"player1 pong card:"<<endl;
    clear_();
    for(int i=0;i<pong1.size();i++)  //cout<<pong1[i]<<" ";
        cout<<tile_(pong1[i])<<" ";
        cout<<endl;
        cout<<"整理後:";
        sort_();
    cout<<endl;
    cout<<endl;
    cout<<"player2 pong card:"<<endl;
    clear_();
    for(int i=0;i<pong2.size();i++) // cout<<pong2[i]<<" ";
        cout<<tile_(pong2[i])<<" ";
        cout<<endl;
        cout<<"整理後:";
        sort_();
    cout<<endl;
    cout<<endl;
    cout<<"player3 pong card:"<<endl;
    clear_();
    for(int i=0;i<pong3.size();i++) // cout<<pong3[i]<<" ";
        cout<<tile_(pong3[i])<<" ";
        cout<<endl;
        cout<<"整理後:";
        sort_();
    cout<<endl;
    cout<<endl;
    cout<<"player4 pong card:"<<endl;
    clear_();
    for(int i=0;i<pong4.size();i++) // cout<<pong4[i]<<" ";
        cout<<tile_(pong4[i])<<" ";
        cout<<endl;
        cout<<"整理後:";
        sort_();
    cout<<endl;
//-------------------------------------------------------------------------------
    cout<<endl;
    cout<<"player1 gong card:"<<endl;
    clear_();
    for(int i=0;i<gong1.size();i++)  //cout<<gong1[i]<<" ";
        cout<<tile_(gong1[i])<<" ";
        cout<<endl;
        cout<<"整理後:";
        sort_();
    cout<<endl;
    cout<<endl;
    cout<<"player2 gong card:"<<endl;
    clear_();
    for(int i=0;i<gong2.size();i++) // cout<<gong2[i]<<" ";
        cout<<tile_(gong2[i])<<" ";
        cout<<endl;
        cout<<"整理後:";
        sort_();
    cout<<endl;
    cout<<endl;
    cout<<"player3 gong card:"<<endl;
    clear_();
    for(int i=0;i<gong3.size();i++) // cout<<gong3[i]<<" ";
        cout<<tile_(gong3[i])<<" ";
        cout<<endl;
        cout<<"整理後:";
        sort_();
    cout<<endl;
    cout<<endl;
    cout<<"player4 gong card:"<<endl;
    clear_();
    for(int i=0;i<gong4.size();i++) // cout<<gong4[i]<<" ";
        cout<<tile_(gong4[i])<<" ";
        cout<<endl;
        cout<<"整理後:";
        sort_();
    cout<<endl;


//-------------------------------------------------------------------------------
    cout<<endl;
    cout<<"series action of every players:"<<endl;
    cout<<endl;
    cout<<"player1's action:"<<endl;
    for(int i=0;i<act1.size();i++) {    //cout<<act1[i]<<" "<<endl;
           stringstream sss(act1[i]);
           string str="";
           int count=0;
           bool for_gong=false;
           while(sss>>str){
                count++;
                if(str=="/gong")
                    for_gong=true;

                if(for_gong==true&&count>=4){}


                if(for_gong==false&&count>=3)
                    cout<<tile_(stoi(str))<<" ";


                else
                    cout<<str<<" ";

           }
        cout<<endl;
    }
    cout<<endl;
    cout<<"player2's action:"<<endl;
    for(int i=0;i<act2.size();i++){  //cout<<act2[i]<<" "<<endl;
           stringstream sss(act2[i]);
           string str="";
           int count=0;
           while(sss>>str){
                count++;
                if(count>=3){
                    cout<<tile_(stoi(str))<<" ";

                }
                else
                    cout<<str<<" ";

           }
        cout<<endl;
    }
    cout<<endl;
    cout<<"player3's action:"<<endl;
    for(int i=0;i<act3.size();i++){  //cout<<act3[i]<<" "<<endl;
           stringstream sss(act3[i]);
           string str="";
           int count=0;
           while(sss>>str){
                count++;
                if(count>=3){
                    cout<<tile_(stoi(str))<<" ";

                }
                else
                    cout<<str<<" ";

           }
        cout<<endl;
    }
    cout<<endl;
    cout<<"player4's action:"<<endl;
    for(int i=0;i<act4.size();i++){  //cout<<act4[i]<<" "<<endl;
           stringstream sss(act4[i]);
           string str="";
           int count=0;
           while(sss>>str){
                count++;
                if(count>=3){
                    cout<<tile_(stoi(str))<<" ";

                }
                else
                    cout<<str<<" ";

           }
        cout<<endl;
    }
    cout<<endl;
    print_mo_cnt();
    print_sum();
    //cout<<"host: player"<<host<<endl;
}
int main(){
    read_write();
    int line=0,my_ID=0,host,now=1;
    for(int i=0;i<21;i++)
        step[i]=0;

    for(int i = 0; i < rs.size(); i ++){
        if(rs[i]==split){
            print_every();
            cout<<split<<now<<endl;
            clear_();
            clear_for_everything();
            my_card.clear();
            had_round=0;
            now++;
            winner=0;
            //p1_step=0,p2_step=0,p3_step=0,p4_step=0;
        }
        stringstream ss(rs[i]);
        string str ="";
        bool throw_ =false,card=false,mo=false,eat=false,pong=false,hu=false,game=false;
        bool gong=false,light_gong=false,dark_gong=false,add_gong=false;
        bool start=false;
        int record=0,cnt=1,last_throw;

        while(ss>>str){

            if(str=="/start"){//my player id
                start=true;
                cnt++;
                continue;
            }
            if(start==true&&cnt==2){
                cnt++;
                continue;
            }
            if(start==true&&cnt==3){
                my_ID=stoi(str);
                break;
            }
//getCommand:
            if(str=="getCommand:"){
                break;
            }
//iniGame
            if(str=="/initGame"){
                game=true;
                cnt++;
                continue;
            }
            if(game==true)
                cnt++;
            if(game==true&&cnt==6){
                host=stoi(str);

                break;
            }
//my initial card
            if(str=="/initCard"){
                card=true;
                continue;
            }
            if(card==true){
                my_card.push_back(stoi(str));
               //cout<<"size:"<<my_card.size()<<endl;
               //cout<<s<<endl;
                continue;
            }

//mo
            if(str=="/mo"){
                mo=true;
                continue;
            }
            if(mo==true){
                my_card.push_back(stoi(str));
                cout<<"now my card(update after /mo):";
                clear_();
                for(int i=0;i<my_card.size();i++)
                    tile_(my_card[i]);

                sort_();

                cout<<endl;

            }
//eat
            if(str=="/eat"){
                eat=true;
                cnt++;
                continue;

            }
            if(eat==true&&cnt==2){
                record=stoi(str);
                cnt++;
                continue;
            }
            if(eat==true&&cnt>=3){

                 if(record==1){
                    eat1.push_back(stoi(str));
                    if(cnt==3)act1.push_back(rs[i]);
                 }
                 if(record==2){
                    eat2.push_back(stoi(str));
                    if(cnt==3)act2.push_back(rs[i]);
                 }
                 if(record==3){
                    eat3.push_back(stoi(str));
                    if(cnt==3)act3.push_back(rs[i]);
                 }
                 if(record==4){
                    eat4.push_back(stoi(str));
                    if(cnt==3)act4.push_back(rs[i]);
                 }
                 cnt++;
                continue;
            }
            if(eat==true&&record==my_ID&&cnt==5){
                 my_card.push_back(stoi(str));
                 continue;
                 //cnt++;
            }
//pong
            if(str=="/pong"){
                pong=true;
                cnt++;

                continue;

            }
            if(pong==true&&cnt==2){
                record=stoi(str);

                if(record==my_ID){
                   my_card.push_back(last_throw);

                }
                cnt++;

                continue;
            }
            if(pong==true&&cnt>=3){
                if(record==1){
                    pong1.push_back(stoi(str));

                    if(cnt==3)act1.push_back(rs[i]);
                }
                if(record==2){
                    pong2.push_back(stoi(str));

                    if(cnt==3)act2.push_back(rs[i]);
                }
                if(record==3){
                    pong3.push_back(stoi(str));

                    if(cnt==3)act3.push_back(rs[i]);
                }
                if(record==4){
                    pong4.push_back(stoi(str));

                    if(cnt==3)act4.push_back(rs[i]);
                }

                cnt++;
                continue;

            }
//gong
            if(str=="/gong"){
                gong=true;
                cnt++;
                continue;
            }
            if(gong==true&&cnt==2){
                record=stoi(str);
                cnt++;
                continue;

            }
            if(gong==true&&cnt==3){
                if(str=="4")
                    light_gong=true;
                if(str=="0")
                    dark_gong=true;
                if(str=="1")
                    add_gong=true;

                cnt++;
                continue;
            }
            if(gong==true&&cnt>=4){
                if(light_gong==true){
                    if(record==1){
                        gong1.push_back(stoi(str));
                        gong_cnt1++;
                        if(cnt==4)act1.push_back(rs[i]);
                        cnt++;
                    }
                    if(record==2){
                        gong2.push_back(stoi(str));
                        gong_cnt2++;
                        if(cnt==4)act2.push_back(rs[i]);
                        cnt++;
                    }
                    if(record==3){
                        gong3.push_back(stoi(str));
                        gong_cnt3++;
                        if(cnt==4)act3.push_back(rs[i]);
                        cnt++;
                    }
                    if(record==4){
                        gong4.push_back(stoi(str));
                        gong_cnt4++;
                        if(cnt==4)act4.push_back(rs[i]);
                        cnt++;
                    }

                }
                if(add_gong==true){

                    if(record==1){

                        gong_cnt1++;
                        add_gong_cnt1++;
                        for(int i=0;i<4;i++)
                            gong1.push_back(stoi(str));
                        int flag=pong1.size();
                        for(int i=0;i<pong1.size();i++){

                            if(pong1[i]==stoi(str)){
                                pong1.erase(pong1.begin()+i);

                            }

                        }

                        if(cnt==4)act1.push_back(rs[i]);
                        cnt++;
                    }
                    if(record==2){
                        gong_cnt2++;
                        add_gong_cnt2++;
                        for(int i=0;i<4;i++)
                            gong2.push_back(stoi(str));
                        for(int i=0;i<pong2.size();i++){

                            if(pong2[i]==stoi(str))
                                pong2.erase(pong2.begin()+i);

                        }

                        if(cnt==4)act2.push_back(rs[i]);
                        cnt++;
                    }
                    if(record==3){
                        gong_cnt3++;
                        add_gong_cnt3++;
                        for(int i=0;i<4;i++)
                            gong3.push_back(stoi(str));
                        for(int i=0;i<pong3.size();i++){

                            if(pong3[i]==stoi(str))
                                pong3.erase(pong3.begin()+i);

                        }

                        if(cnt==4)act3.push_back(rs[i]);
                        cnt++;
                    }
                    if(record==4){
                        gong_cnt4++;
                        add_gong_cnt4++;
                        for(int i=0;i<4;i++)
                            gong4.push_back(stoi(str));
                        for(int i=0;i<pong4.size();i++){

                            if(pong4[i]==stoi(str))
                                pong4.erase(pong4.begin()+i);

                        }

                        if(cnt==4)act4.push_back(rs[i]);
                        cnt++;
                    }

                }
                if(dark_gong==true){
                    if(record==1){
                            if(cnt==4){
                                act1.push_back(rs[i]);
                                gong_cnt1++;
                            }

                        if(my_ID==record&&cnt>=4){
                            gong1.push_back(stoi(str));
                            cnt++;
                            continue;

                        }

                    }
                    if(record==2){
                            if(cnt==4){
                                act2.push_back(rs[i]);
                                gong_cnt2++;
                            }
                        if(my_ID==record&&cnt>=4){
                            gong2.push_back(stoi(str));
                            cnt++;
                            continue;

                        }

                    }
                    if(record==3){
                            if(cnt==4){
                                act3.push_back(rs[i]);
                                gong_cnt3++;
                            }

                        if(my_ID==record&&cnt>=4){
                            gong3.push_back(stoi(str));
                            cnt++;
                            continue;

                        }
                    }
                    if(record==4){
                            if(cnt==5){
                                act4.push_back(rs[i]);
                                gong_cnt4++;
                            }
                            if(my_ID==record&&cnt>=4){
                            gong4.push_back(stoi(str));
                            cnt++;
                            continue;

                        }


                    }



                }


            }
//throw
            if(str=="/throw"){
                throw_=true;
                had_round++;
                cnt++;
                cout<<rs[i]<<endl;
                continue;
            }
            if(throw_==true&&cnt==2){
                record=stoi(str);
                cnt++;
                continue;
            }
            if(throw_==true&&record==1&&cnt==3){

                mo_cnt1++;
                player1.push_back(stoi(str));
                act1.push_back(rs[i]);

            }
            if(throw_==true&&record==2&&cnt==3){

                mo_cnt2++;
                player2.push_back(stoi(str));
                act2.push_back(rs[i]);
            }

            if(throw_==true&&record==3&&cnt==3){

                mo_cnt3++;
                player3.push_back(stoi(str));
                act3.push_back(rs[i]);
            }

            if(throw_==true&&record==4&&cnt==3){

                mo_cnt4++;
                player4.push_back(stoi(str));
                act4.push_back(rs[i]);

            }
            int calculate,cal2,temp;
            if(throw_==true&&record==my_ID&&cnt==3){//my throw's card
                int index;
                for(int i=0;i<my_card.size();i++){
                    if(my_card[i]==stoi(str)){
                        index=i;
                        calculate=my_card[i]/100;
                        temp=my_card[i]%100;
                        cal2=temp/10;
                        //cout<<"index="<<i<<endl;
                    }
                }

                my_card.erase(my_card.begin()+index);


                if(calculate==1){
                    for(int i=0;i<w.size();i++){
                        if(stoi(w[i])==cal2)
                             index=i;
                    }
                    clear_();
                    for(int j=0;j<my_card.size();j++)
                        tile_(my_card[j]);

                  //  w.erase(w.begin()+index);

                }

                else if(calculate==2){
                    for(int i=0;i<t.size();i++){
                        if(stoi(t[i])==cal2)
                             index=i;
                    }
                    clear_();
                    for(int j=0;j<my_card.size();j++)
                        tile_(my_card[j]);

                   // t.erase(t.begin()+index);

                }
                else if(calculate==3){
                    for(int i=0;i<s.size();i++){
                        if(stoi(s[i])==cal2)
                             index=i;
                    }
                    clear_();
                    for(int j=0;j<my_card.size();j++)
                        tile_(my_card[j]);

                  //  s.erase(s.begin()+index);

                }
                else if(calculate==4){


                    for(int i=0;i<ch.size();i++){
                        if(ch[i]==word[cal2-1])//cal2=6
                             index=i;

                    }
                    clear_();
                    for(int j=0;j<my_card.size();j++)
                        tile_(my_card[j]);

                   // ch.erase(ch.begin()+index);


                }

            }
            if(cnt==3&&throw_==true)
                last_throw=stoi(str);
//hu
            if(str=="/hu"){
                cout<<"total round play in this game:"<<had_round<<endl;
                hu=true;
                cnt++;
                continue;
            }
            if(hu==true&&cnt==2){
                record=stoi(str);
                winner=stoi(str);
                cnt++;
                continue;
            }
            if(hu==true&&cnt==3&&my_ID==record){
                my_card.push_back(stoi(str));
                cnt++;
            }
        }//split string



}//for rs

    fstream  myfile;

    cout<<"win in sum of eat,pong,gong=0: "<<win_sum_0<<endl;
    myfile.open("sum_of_eat_pong_gong_0.txt",ios::app);
    myfile <<to_string(win_sum_0)<<"\n";
    myfile.close();

    cout<<"win in sum of eat,pong,gong=1: "<<win_sum_1<<endl;
    myfile.open("sum_of_eat_pong_gong_1.txt",ios::app);
    myfile <<to_string(win_sum_1)<<"\n";
    myfile.close();

    cout<<"win in sum of eat,pong,gong=2: "<<win_sum_2<<endl;
    myfile.open("sum_of_eat_pong_gong_2.txt",ios::app);
    myfile <<to_string(win_sum_2)<<"\n";
    myfile.close();

    cout<<"win in sum of eat,pong,gong=3: "<<win_sum_3<<endl;
    myfile.open("sum_of_eat_pong_gong_3.txt",ios::app);
    myfile <<to_string(win_sum_3)<<"\n";
    myfile.close();

    cout<<"win in sum of eat,pong,gong=4: "<<win_sum_4<<endl;
    myfile.open("sum_of_eat_pong_gong_4.txt",ios::app);
    myfile <<to_string(win_sum_4)<<"\n";
    myfile.close();

    cout<<"win in sum of eat,pong,gong=5: "<<win_sum_5<<endl;
    myfile.open("sum_of_eat_pong_gong_5.txt",ios::app);
    myfile <<to_string(win_sum_5)<<"\n";
    myfile.close();


    cout<<"throw card (number3~7) in every step(throw):"<<endl;

    fstream new_file;


    for(int i=1;i<21;i++){
        string str="output"+to_string(i)+".txt";
        new_file.open(str,ios::app);
        new_file<<step[i]<<"\n";
        cout<<i<<"step:"<<step[i]<<endl;
        new_file.close();
    }



    cout<<"DONE"<<endl;
    return 0;



}
