快手后台笔试编程题 过3.6
//第一题
// IT笔试.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <bitset>
#include <stack>
using namespace std;
int main0()
{
string strScan;
char cScan;
vector<char> vecScan;
vector<vector<char>> vecvecScan;
int nFlag = 0;
while (cin>>cScan)
{
if (cScan != '.' && cScan != ':')
{
vecScan.push_back(cScan);
}
else if (cScan == '.')
{
if (nFlag == 0)
{
nFlag = 4;
}
else
{
if (nFlag == 6)
{
cout << "Neither" << endl;
return 0;
}
}
if (vecScan.size() == 0 || vecScan.size() > 3)
{
cout << "Neither" << endl;
return 0;
}
if (vecScan.size() > 1 && vecScan[0] == '0')
{
cout << "Neither" << endl;
return 0;
}
string str1 = "";
for (auto i : vecScan)
{
if (i > '9' || i < '0')
{
cout << "Neither" << endl;
return 0;
}
str1 += i;
}
int nNum = stoi(str1);
if (nNum > 255)
{
cout << "Neither" << endl;
return 0;
}
vecScan.clear();
}
else if (cScan == ':')
{
if (nFlag == 0)
{
nFlag = 6;
}
else
{
if (nFlag == 4)
{
cout << "Neither" << endl;
return 0;
}
}
if (vecScan.size() == 0 || vecScan.size() > 4)
{
cout << "Neither" << endl;
return 0;
}
vecScan.clear();
}
}
if (nFlag == 4)
{
if (vecScan.size() == 0 || vecScan.size() > 3)
{
cout << "Neither" << endl;
return 0;
}
if (vecScan.size() > 1 && vecScan[0] == '0')
{
cout << "Neither" << endl;
return 0;
}
string str1 = "";
for (auto i : vecScan)
{
if (i > '9' || i < '0')
{
cout << "Neither" << endl;
return 0;
}
str1 += i;
}
int nNum = stoi(str1);
if (nNum > 255)
{
cout << "Neither" << endl;
return 0;
}
cout << "IPv4" << endl;
}
else
{
if (vecScan.size() == 0 || vecScan.size() > 4)
{
cout << "Neither" << endl;
return 0;
}
cout << "IPv6" << endl;
}
system("pause");
return 0;
}
//第二题
#include "stdafx.h"
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <bitset>
#include <stack>
using namespace std;
map<int, vector<char>> map_Nums{ make_pair(2,vector<char>{ 'a','b','c' }),
make_pair(3,vector<char>{ 'd','e','f' }) ,make_pair(4,vector<char>{ 'g','h','i' }) ,make_pair(5,vector<char>{ 'j','k','l' }) ,make_pair(6,vector<char>{ 'm','n','o' }) ,make_pair(7,vector<char>{ 'p','q','r','s' }) ,make_pair(8,vector<char>{ 't','u','v' }) ,make_pair(9,vector<char>{ 'w','x','y','z' }) };
bool bFlag = false;
void getResult(string &strCin, int n, string strTem)
{
if (n >= strCin.size())
{
return;
}
int nTem = strCin[n] - '0';
for (auto i : map_Nums[nTem])
{
if (n == strCin.size() - 1)
{
if (bFlag)
{
cout << ", " << strTem + i;
}
else
{
bFlag = true;
cout << strTem + i;
}
}
else
{
getResult(strCin, n + 1, strTem + i);
}
}
return;
}
int main1()
{
string strCin;
string strTem;
getline(cin, strCin);
cout << '[';
getResult(strCin, 0, strTem);
cout << ']' << endl;
system("pause");
return 0;
} //第三题
#include "stdafx.h"
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <bitset>
#include <stack>
using namespace std;
int cmp(int n1, int n2)
{
if (n1 >= n2)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int nNum;
vector<int> vecNums;
cin >> nNum;
int nTem;
while (nNum--)
{
cin >> nTem;
vecNums.push_back(nTem);
}
sort(vecNums.begin(), vecNums.end(), cmp);
int nNum1 = 0, nNum2 = 0;
for (auto i : vecNums)
{
if (nNum1 > nNum2)
{
nNum2 += i;
}
else
{
nNum1 += i;
}
}
int nResult;
if (nNum1 - nNum2 > 0)
{
nResult = nNum1 - nNum2;
}
else
{
nResult = nNum2 - nNum1;
}
cout << nResult << endl;
return 0;
} //第四题来不及 //判断N,大于4,输出5,否则,输出1; //结果通过60%
#笔试题目##快手##题解##C++工程师##校招#

