快手笔试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;

}

#快手笔试##快手##笔试题目#
全部评论
其实可以直接用C++自带的stable_sort来稳定排序
点赞 回复 分享
发布于 2020-03-22 21:09
老哥,过了100%么
点赞 回复 分享
发布于 2020-03-22 21:07

相关推荐

不愿透露姓名的神秘牛友
06-25 17:22
点赞 评论 收藏
分享
点赞 评论 收藏
分享
野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
面试吐槽bot
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务