#include <iostream> #include <string.h> using namespace std; int main(){ int length[9]={5,5,4,4,4,4,4,4,4}; string **s=new string*[9]; s[0]=new string[5]{"1B", "1B", "FO", "GO", "1B"}; s[1]=new string[5]{"1B", "2B", "FO", "FO", "SO"}; s[2]=new string[4]{"SO", "HR", "SO", "1B"}; s[3]=new string[4]{"FO", "FO", "FO", "HR"}; s[4]=new string[5]{"1B", "1B", "1B", "1B"}; s[5]=new string[6]{"GO", "GO", "3B", "GO"}; s[6]=new string[4]{"1B", "GO", "GO", "SO"}; s[7]=new string[4]{"SO", "GO", "2B", "2B"}; s[8]=new string[4]{"3B", "GO", "GO", "FO"}; int out=0; cout<<"請輸入出局數 : "; scanf("%d", &out); int total=0; for (int i=0;i<9;i++){ total+=length[i]; } //直線化 int *ball=new int[total]{0}; for (int i=0;i<9;i++){ for (int j=0;j<length[i];j++){ if(s[i][j].compare("1B")==0) ball[j*9+i]=1; else if(s[i][j].compare("2B")==0) ball[j*9+i]=2; else if(s[i][j].compare("3B")==0) ball[j*9+i]=3; else if(s[i][j].compare("HR")==0) ball[j*9+i]=4; else ball[j*9+i]=5; } } //切段 int r=0, c=0; int outCount=0; int game[10][10]={0}; for (int i=0;i<total;i++){ game[r][c++]=ball[i]; if(ball[i]==5)outCount++; if(outCount==3){ r++; c=0; outCount=0; } } //每列往後加, 超過4, 分數就加1 outCount=0; int score=0; bool stop=false; for (int i=0;i<10;i++){ for (int j=0;game[i][j]!=0;j++){ if(game[i][j]!=5){ int tmp=game[i][j]; for (int k=j+1;k<10;k++){ if(game[i][k]!=5){ tmp+=game[i][k]; if(tmp>=4){ score++; break; } } } } else{ outCount++; if(outCount==out){ stop=true; break; } } } if(stop)break; } printf("score : %d\n\n", score); printf("for checking\n"); for (int i=0;i<10;i++){ for (int j=0;j<10;j++){ printf("%d ", game[i][j]); } printf("\n"); } }