2、福彩3D是3位数字,可以重复,给出3位数的全排列,并且列出全部重复的数字,有两个重复的数字。
#include <stdio.h>
std::vector<string> v3dAllNum;
template <class Type>
Type stringToNum(const string& str)
{
istringstream iss(str);
Type num;
iss >> num;
return num;
}
template <class T>
string to_string(T _Val)
{
ostringstream __os;
__os<<_Val;
string str = __os.str(); //得到 string
return str;
}
int IsABBA(int* num, int len)
{
int b = -1;
// int j = 0;
if ( num[0] == num[1] )
{
if ( num[1] != num[2] ) {
b = 1; //AAB
return b;
}
else
{
//AAA
b = 2;
return b;
}
}
else
{
if ( num[1] == num[2] )
{
//ABB
b = 3;
return b;
}
else if ( num[0] == num[2] )
{
//ABA
b = 4;
return b;
}
else
{
//ABC
b = 5;
return b;
}
}
}
int main(int argc, char *argv[])
{
for (unsigned int i = 0; i < 9; i++) {
for (unsigned int j = 0; j < 9; j++) {
for (unsigned int n = 0; n < 9; n++) {
v3dAllNum.push_back( to_string(i) + to_string(j) + to_string(n) );
}
}
}
}
string strResult;
for (std::vector<String>::iterator it = v3dAllNum.begin();it!=v3dAllNum.end();) {
int one = stringToNum(*it)/100;
int two = stringToNum((*it)/10%10;
int three = stringToNum(*it)%10;
int sNum[3] = {0};
sNum[0] = one;
sNum[1] = two;
sNum[2] = three;
int iRet = IsABBA(sNum, 3);
if ( 2 == iRet ) {
strResult = "豹子";
}
else if (5 == iRet) {
strResult = "无重复号";
}
else
{
strResult = "有重复号";
}
}
return 0;
}