快手笔试A第3题
找出价值电话号
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool isDear(string& str, int& b)
{
string s = str.substr(3, 8);
int fb=1;
int fs1=1; //递增顺
int fs2=1;
for(int i=1; i<8; i++)
{
if(s[i]==s[i-1])
{
fb++;
if(b < (fb*2+1))
{
b = fb*2+1;
}
fs1=1;
fs2=1;
}
else if(s[i] - s[i-1] == 1)
{
fs1++;
if(b < (fs1*2))
{
b = fs1*2;
}
fb=1;
fs2=1;
}
else if(s[i-1] - s[i] == 1)
{
fs2++;
if(b < (fs2*2))
{
b = fs2*2;
}
fs1=1;
fb=1;
}
else
{
fb=1;
fs1=1;
fs2=1;
}
}
if(b >= 6)
{
return true;
}
return false;
}
bool compare(pair<int, string>& p1, pair<int, string>& p2)
{
return p1.first > p2.first;
}
int main()
{
string str;
getline(cin, str);
int size = str.size();
int nums = (size+1)/12;
vector<string> vec;
for(int i=0; i<nums; i++)
{
vec.push_back(str.substr(i*12, 11));
}
vector<pair<int, string> > res;
for(int i=0; i<nums; i++)
{
int b=0;
if(isDear(vec[i], b))
{
res.push_back(make_pair(b, vec[i]));
}
}
if(res.empty())
{
cout<<"null"<<endl;
}
else
{
sort(res.begin(), res.end(), compare);
for(int i=0; i<res.size()-1; i++)
{
cout<<res[i].second<<',';
}
cout<<res[res.size()-1].second<<endl;
}
return 0;
}