搜狗笔试
今天2019.09.17,昨天晚上搜狗笔试,看起来题面很简单,但实际上暗藏玄机。
第1个题,判断IP是否合法,知道用正则表达式来求解会很简单,但不熟,直接分解字符串做的, 100%AC。
第2个题,根据规则解密码,据说线段树可以实现100%AC,但直接按题面做的,且类型用的int,没用long,出现0 AC的情况。
有个牛油的思路不错,代码链接贴在这 https://blog.csdn.net/weixin_39843989/article/details/100900833
附自己的代码如下,仅供交流使用。
----------------------------------------------------------------------------- 第一题 ---------------------------------------------------------------------------
int main()
{
int N, M;
cin >> N >> M;
cin.get();
vector<string> vstrFilters;
while (N--)
{
string strIn;
getline(cin, strIn);
vstrFilters.push_back(strIn);
}
vector<string> vstrJudging;
while (M--)
{
string strIn;
getline(cin, strIn);
vstrJudging.push_back(strIn);
}
vector<int> vFlags(vstrJudging.size(), 0);
for (int i = 0; i < vstrJudging.size(); i++)
{
bool bFlag = false;
for (int j = 0; j < vstrFilters.size(); j++)
{
int nIdx = vstrFilters[j].find('*');
if (-1 == nIdx)
{
if (vstrJudging[i] == vstrFilters[j])
{
bFlag = true;
break;
}
else
continue;
}
else
{
string strPrev = vstrFilters[j].substr(0, nIdx);
string strLatt = vstrFilters[j].substr(nIdx + 1, vstrFilters[j].length() - nIdx - 1);
int n = vstrJudging[i].find(strPrev);
int m = vstrJudging[i].rfind(strLatt);
if (!strPrev.empty() && !strLatt.empty())
{
if (vstrJudging[i].find(strPrev) == 0 && vstrJudging[i].rfind(strLatt) == vstrJudging[i].length() - strLatt.length())
{
bFlag = true;
break;
}
}
else if (strPrev.empty() && !strLatt.empty())
{
if (vstrJudging[i].rfind(strLatt) == vstrJudging[i].length() - strLatt.length())
{
bFlag = true;
break;
}
}
else if (!strPrev.empty() && strLatt.empty())
{
if (vstrJudging[i].find(strPrev) == 0)
{
bFlag = true;
break;
}
}
else
{
bFlag = true;
break;
}
}
}
if (bFlag)
{
vFlags[i] = 1;
}
}
for (int i = 0; i < vFlags.size() - 1; i++)
{
cout << vFlags[i] << " ";
}
cout << vFlags[vFlags.size() - 1] << endl;
system("pause");
return 0;
} ----------------------------------------------------------------------------- 第二题 ---------------------------------------------------------------------------#include<iostream>
#include<vector>
using namespace std;
typedef struct INTPAIR
{
int nLi;
int nRi;
}STPAIR;
int main()
{
int N, M;
cin >> N >> M;
vector<STPAIR> vstPairs;
vector<int> vIns(N, 0);
while (M--)
{
STPAIR stPair;
cin >> stPair.nLi >> stPair.nRi;
vstPairs.push_back(stPair);
}
int nRes = 0;
for (int i = 0; i < vstPairs.size(); i++)
{
for (int j = vstPairs[i].nLi + 1 ; j <= vstPairs[i].nRi + 1; j++)
{
vIns[j] = i;
}
}
for (int i = 0; i < vIns.size(); i++)
{
nRes += i * vIns[i];
}
cout << nRes % 100000009 << endl;
system("pause");
return 0;
} 
查看14道真题和解析