网易游戏 编程题一直显示段错误,哪路神仙帮忙分析下原因



#include <iostream>
#include <vector>
#include <string>
#include <map>

int main()
{
int LogNumber = 0;
std::cin >> LogNumber;

if (LogNumber == 0)
{
std::cout << "ERROR" << std::endl;
system("pause");
return 0;
}

std::vector <std::pair<std::string, std::string>> LogVec;
for (int i = 0; i < LogNumber; i++)
{
std::string TempLog = " ", TempTime = " ", TempId = " ";
std::cin >> TempTime >> TempId >> TempLog;
LogVec.push_back(std::make_pair(TempId, TempLog));
}

int CommendNumber = 0;
std::cin >> CommendNumber;

if (CommendNumber == 0)
{
std::cout << "ERROR" << std::endl;
system("pause");
return 0;
}
std::vector<std::map<std::string, std::string>> CommendVec;

for (int i = 0; i < CommendNumber; i++)
{
int TempCommendHang = 0;
std::cin >> TempCommendHang;
if (TempCommendHang == 0)
{
std::cout << "ERROR" << std::endl;
return 0;
}
std::map<std::string, std::string> TempMap;
bool IsEx = false;
for (int k = 0; k < TempCommendHang; k++)
{
std::string TempCom = " ", Value = " ";
std::cin >> TempCom >> Value;
if (TempCom == "--search")
{
TempMap.insert(std::make_pair("--search", Value));
IsEx = true;
}
if (TempCom == "--hostid")
TempMap.insert(std::make_pair("--hostid", Value));
if (TempCom == "--before")
TempMap.insert(std::make_pair("--before", Value));
if (TempCom == "--after")
TempMap.insert(std::make_pair("--after", Value));
}
if (IsEx == false)
{
std::cout << "ERROR" << std::endl;
return 0;
}

CommendVec.push_back(TempMap);
}

for (int i = 0; i < CommendVec.size(); i++)
{
std::vector<std::string> outData;
int CurrentId = -1;
std::string Log = "";
if (CommendVec[i].find("--hostid") != CommendVec[i].end())
{
for (int k = 0; k < LogVec.size(); k++)
{
if (CommendVec[i]["--hostid"] == LogVec[k].first)
{
std::string CurrentLog = LogVec[k].second;
if (CurrentLog.find(CommendVec[i]["--search"]) != -1)
{
//outData.push_back(LogVec[k].second);
Log = LogVec[k].second;
CurrentId = k;
break;
}
}
}
}
else
{
for (int k = 0; k < LogVec.size(); k++)
{
std::string CurrentLog = LogVec[k].second;
if (CurrentLog.find(CommendVec[i]["--search"]) != -1)
{
//outData.push_back(LogVec[k].second);
Log = LogVec[k].second;
CurrentId = k;
break;
}
}
}

if (CommendVec[i].find("--before") != CommendVec[i].end())
{
int aa = std::stoi(CommendVec[i]["--before"]);
for (int k = CurrentId - std::stoi(CommendVec[i]["--before"]); k <= CurrentId; k++)
{
outData.push_back(LogVec[k].second);
}
}

if (CommendVec[i].find("--after") != CommendVec[i].end())
{
for (int k = CurrentId + 1; k <= LogVec.size() - 1 && k <= CurrentId + std::stoi(CommendVec[i]["--after"]); k++)
{
outData.push_back(LogVec[k].second);
}
}

if (CurrentId == -1)
{
if (outData.empty())
{
std::cout << "ERROR" << std::endl;
continue;
}
}
else
{
if (outData.empty())
{
outData.push_back(Log);
}
}

for (int k = 0; k < outData.size(); k++)
{
std::cout << outData[k] << std::endl;
}
}

system("pause");
return 0;
}

网易初级游戏研发工程师,第二题。一直段错误,哪路神仙帮我看下
#网易#
全部评论

相关推荐

点赞 评论 收藏
分享
专心打鱼:互联网搬运工,贴子都要偷
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务