# 我解2006百度之星程序设计大赛之蝈蝈计分

＃include <string>
＃include <vector>
＃include <fstream>
＃include <queue>
＃include <iostream>
＃include <stdio.h>
＃include "math.h"

using namespace std;

struct score
{
char left;
char right;
};

vector< vector<char> > record;
queue< vector<char> > testRecord;
vector< vector<char> > finalTestRecord;

bool ReachScore(const char& left, const char& right)
{
if(left >= 21)
{
if(right <= 19)
{
return true;
}
}
if(right >= 21)
{
if(left <= 19)
{
return true;
}
}

if((left >= 22) && (right == left -2))
{
return true;
}
if((right >= 22) && (left == right - 2))
{
return true;
}

return false;
}

vector<score> GetScore(vector<char> vec)
{
char left = 0;
char right = 0;
vector<score> scoreVec;
score mk;
for(size_t i = 0; i < vec.size(); ++i)
{
if(i % 2 == 0)
{
left += vec.at(i);
}
else
{
right += vec.at(i);
}
if(ReachScore(left, right) == true)
{
mk.left = left;
mk.right = right;
scoreVec.push_back(mk);
left = 0;
right = 0;
}
else if (i == vec.size() - 1)
{
scoreVec.clear();
return scoreVec;
}

}
int nLeftScore = 0;
int nRightScore = 0;
for(vector<score>::iterator iter = scoreVec.begin();
iter != scoreVec.end();
++iter)
{
if((*iter).left > (*iter).right)
{
++nLeftScore;
}
else
{
++nRightScore;
}
}
if((nLeftScore == 3 && nRightScore < 3) ||
(nRightScore == 3 && nLeftScore < 3))
{
return scoreVec;
}
else
{
scoreVec.clear();
return scoreVec;
}
}

void GetScore()
{
vector<score> temp;
vector<char> chvec;

for(size_t i = 0; i < testRecord.size(); ++i)
{
chvec = testRecord.front();
testRecord.pop();
temp = GetScore(chvec);
if(temp.size() == 0)
{
cout << "/nUNKNOWN/n/n";
return;
}
else
{
for(vector<score>::iterator iter = temp.begin(); iter != temp.end(); ++iter)
{
cout << (int)(*iter).left << ":" << (int)(*iter).right << endl;
}
return;
}
}
}

int main(int argc, char* argv[])
{
ifstream is(argv[1], ios::in | ios::binary);
int nMatch = 0;
is >> nMatch;
for(int nMatchIndex = 0; nMatchIndex < nMatch; ++nMatchIndex)
{
int nChar = 0;
is >> nChar;
vector<char> recordPerMatch;
unsigned char ch = 0;
for(int nCharIndex = 0; nCharIndex < nChar; ++nCharIndex)
{
is >> ch;
if(ch != 'X')
{
recordPerMatch.push_back(ch - 48);
}
else
{
recordPerMatch.push_back('X');
}
}
record.push_back(recordPerMatch);
recordPerMatch.clear();
}

for(int nMatchIndex = 0; nMatchIndex < nMatch; ++nMatchIndex)
{
testRecord.push(record[nMatchIndex]);
for( ; ; )
{
vector<char> temp = testRecord.front();
vector<char> temp1(temp);
vector<char> temp2(temp);
bool tag = false;
for(vector<char>::iterator iter = temp1.begin();
iter != temp1.end();
++iter)
{
if((*iter) == 'X')
{
testRecord.pop();
(*iter) = 10;
tag = true;
break;
}
}

if(tag == false)
{
finalTestRecord.push_back(temp1);
break;
}
else
{
testRecord.push(temp1);

for(vector<char>::iterator iter = temp2.begin();
iter != temp2.end();
++iter)
{
if((*iter) == 'X' && (iter+1) != temp2.end())
{
(*iter) = 10 + (*(iter + 1));
temp2.erase(iter + 1);
break;
}
}
testRecord.push(temp2);
}
}
GetScore();
while(testRecord.size())
{
testRecord.pop();
}
}

return 0;
}

#### 2006百度之星程序设计大赛程序题目

2006-06-18 19:30:00

#### 2017"百度之星"程序设计大赛 - 初赛（A）

2017-08-12 19:54:17

#### Astar百度之星程序设计大赛

2008-05-09 15:49:00

#### 历年百度之星程序设计大赛试题题目

2008年06月01日 202KB 下载

#### 2017"百度之星"程序设计大赛-资格赛

2017-08-07 16:27:55

#### 2015年百度之星程序设计大赛 - 初赛(2)【题解】

2015-06-02 16:54:30

#### 2015年百度之星程序设计大赛 - 初赛(1) 【题解】

2015-06-01 19:13:35

#### 百度之星程序设计大赛题目

2011年06月20日 364KB 下载

#### 百度之星程序设计大赛

2009年12月24日 949KB 下载

#### 2015年百度之星程序设计大赛 - 资格赛

2015-05-24 16:50:22