#include<iostream>
#include<cmath>
#include<vector>
#include"dp_max_xulie.h"
using namespace std;
int chupai_cishu = 0;//全局变量
void show(int* arr_clean)
{
//show the detial imformation
for (int i = 1; i < 14; i++)
{
if (arr_clean[i] != 0)
{
cout << i << " " << arr_clean[i] << " ";
}
}
cout << endl;
}
int* zhaoshunzi(int* arr)
{
//开始找顺子
vector<int>shunzi;
vector<vector<int>>shunzi_reslut;
int i=1; int j; int i_i = 0;
while(i)
{
int flag=0;
//--------------------------------
for (j = i; j < 14; j++)
{
if (arr[j] != 0)
shunzi.push_back(j);
//cout << "shunzi.size()"<< shunzi.size() <<j-i+1<<endl;
if (shunzi.size() != (j - i + 1))
{
break;
}
else if (shunzi.size() >= 5)
{
//cout << "I get shunzi!" << shunzi.size() << endl;
flag = 1;//找到顺子
}
}
//--------------------------------
for (int i = 0; i < shunzi.size() && shunzi.size()>=5; i++)
{
for (int j = 0; j < 14; j++)
if (shunzi[i] == j)
{
arr[j]--;
cout << arr[j]<<" ";
}
//cout << endl;
if(i==shunzi.size()-1)
cout << endl;
}
//---------------------------------
//show(arr);//展示顺子
if (shunzi.size() >= 5)
{
shunzi_reslut.push_back(shunzi);//保存多个顺子
}
//cout << "多个顺子" << shunzi_reslut.size()<<endl;
shunzi.clear();
if (flag ==1)
i = 1;
else
i++;
if (i > 10)
break;
}
cout << "多个顺子" << shunzi_reslut.size() << endl;
chupai_cishu += shunzi_reslut.size();//将顺子的个数记录下来
return arr;
}
int sidai = 0;
int* si_dai(int* arr)
{
for (int i = 1; i < 14; i++)
{
if (arr[i] == 4)
{
arr[i] -= 4;
int flagg = 0;
for (int j = 1; j < 14; j++)
{
if (arr[j] == 1)
{
flagg++;
arr[j] -= 1;
//break;
}
if (flagg == 2)
break;
}
for (int j = 1; j < 14; j++)
{
if (arr[j] == 2 && flagg==0)
{
arr[j] -= 2;
break;
}
}
chupai_cishu += 1;
}
}
show(arr);
cout << "sidia " << chupai_cishu << endl;
return arr;
}
int* san_dai(int* arr)
{
for (int i = 1; i < 14; i++)
{
if (arr[i] == 3)
{
arr[i] -= 3;
for (int j = 1; j < 14; j++)
{
if (arr[j] == 1)
{
arr[j] -= 1;
break;
}
}
chupai_cishu += 1;
}
}
//show(arr);
cout << "sidia " << chupai_cishu << endl;
return arr;
}
int* erz(int* arr)
{
for (int i = 1; i < 14; i++)
{
if (arr[i] == 2)
{
arr[i] -= 2;
chupai_cishu += 1;
}
}
//show(arr);
cout << "sidia " << chupai_cishu << endl;
return arr;
}
int* danz(int* arr)
{
for (int i = 1; i < 14; i++)
{
if (arr[i] == 1)
{
arr[i] -= 1;
chupai_cishu += 1;
}
}
show(arr);
cout << "sidia " << chupai_cishu << endl;
return arr;
}
int chupai(string pai)
{
int number = pai.length();
//int* arr = new int[13];//总计13张牌
int arr[14] = { 0 }; // 去掉0 1
vector<int>zhangshu; //牌的张数记录
vector<int>daxiao; //牌的大小记录
for (int i = 0; i < number;i++)
{
if (pai[i] == 'A') arr[1]++;
if (pai[i] == '2') arr[2]++; if (pai[i] == '3') arr[3]++; if (pai[i] == '4') arr[4]++;
if (pai[i] == '5') arr[5]++; if (pai[i] == '6') arr[6]++; if (pai[i] == '7') arr[7]++;
if (pai[i] == '8') arr[8]++; if (pai[i] == '9') arr[9]++; if (pai[i] == '1') { arr[10]++; i++; }
if (pai[i] == 'J') arr[11]++;if (pai[i] == 'Q') arr[12]++;if (pai[i] == 'K') arr[13]++;
}
for (int i = 1; i < 14; i++)
{
if (arr[i] != 0)
{
zhangshu.push_back(arr[i]);//由小到大排列,daxiao[2]='2'的个数
daxiao.push_back(i);
cout << i << " " << arr[i] << endl;;
}
}
cout << "-------------" << endl;
int *arr_clean = zhaoshunzi(arr);
//show the detial imformation
show(arr_clean);
int *sidai_clean = si_dai(arr_clean);
int *sandai_clean= san_dai(sidai_clean);
int* erdai_clean = erz(sandai_clean);
int* dandai_clean= danz(erdai_clean);
return 0;
}
int lengthOfLongestSubstring(string s)
{
int n = s.length();
int* arr = new int[n];
//int arr[8]={1};
for (int i = 0; i < n; i++)
arr[i] = 1;
for (int i = 0; i < n - 1; i++)
{
for (int j = i + 1; j < n; j++)
{
if (arr[i] == 1)
{
if (s[i] == s[j])
arr[j]++;
}
else
break;
}
}
int number_max = 0;
for (int j = 0; j < s.length(); j++)
{
int nameber = 0;
for (int i = j; i < s.length(); i++)
{
if (s[i] == 1)
nameber++;
else
{
j = i - 1;
break;
}
}
if (number_max < nameber)
number_max = nameber;
}
return number_max;
}
int le(string s)
{
int max = 0;
int i = 0;
int size = s.size();
for (int j = 0; j < size; j++)
{
for (int k = i; k < j; k++)
{
if (s[k] == s[j])
{
max = max > (j - i) ? max : j - i;//不包括j
i = k + 1;
}
}
max = max > (j - i + 1) ? max : j - i + 1;//包括j
}
return max;
}
int expandAroundCenter(string s, int left, int right)
{
int L = left, R = right;
while (L >= 0 && R < s.length() && s[L] == s[R])
{// 计算以left和right为中心的回文串长度
L--;
R++;
}
return R - L - 1;
}
string longestPalindrome(string s)
{
if (s.length() < 1)
{
return "";
}
int start = 0, end = 0;
for (int i = 0; i < s.length(); i++)
{
int len1 = expandAroundCenter(s, i, i);//一个元素为中心
int len2 = expandAroundCenter(s, i, i + 1);//两个元素为中心
int len = max(len1, len2);
if (len > end - start)
{
start = i - (len - 1) / 2;
end = i + len / 2;
}
}
return s.substr(start, end - start + 1);
}
string ongestPalindrome(string s)
{
int max_len1 = 0;
int max_len2 = 0;
int x1 = 0, x2 = 0;//记录下标
int y1 = 0, y2 = 0;//记录下标
int reslut1, reslut2;
int reslut3, reslut4;
int size = s.size();
for (int j = 0; j < size; j++)
{
int max_temp1 = 0;
for (int k1 = j, k2 = j; 0 <= k1 && k2 <= size - 1; k1--, k2++)
{
if (s[k1] == s[k2])
{
x1 = k1;
x2 = k2;
max_temp1 = x2 - x1 + 1;
}
else
break;
if (max_temp1 > max_len1)
{
reslut1 = x1;
reslut2 = x2;
max_len1 = max_temp1;
//cout <<"1:"<<max_len1<< endl;
}
}
int max_temp2 = 0;
for (int k1 = j, k2 = j + 1; 0 <= k1 && k2 <= size - 1; k1--, k2++)
{
if (s[k1] == s[k2])
{
//max_temp1++;
y1 = k1;
y2 = k2;
max_temp2 = y2 - y1 + 1;
}
else
break;
if (max_temp2 > max_len2)
{
reslut3 = y1;
reslut4 = y2;
max_len2 = max_temp2;
//cout <<"2:" <<max_len2 << endl;
}
}
}
//cout << "max_len1 " << max_len1 << " max_len2 " << max_len2 << endl;
//cout << "reslut1 " << reslut1 << " reslut2 " << reslut2<<endl;
//cout << "reslut3 " << reslut3 << " reslut4 " << reslut4 << endl;
if (max_len1 > max_len2)
return s.substr(reslut1, reslut2-reslut1+1);
else
return s.substr(reslut3, reslut4-reslut3+1);
}
using namespace std;
int main()
{
//string pai = "8K67A65K271059K346AK2";
//chupai(pai);
string v = "bbabb";
cout << ongestPalindrome(v);
return 0;
}
斗地主小demo
于 2020-08-12 10:57:26 首次发布