牛客网软件测试机考题库,为什么编程题本地测试通过,可是提交时却总报错。求大神们指点。...

以下是题目要求:

开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。

处理:

1.记录最多8条错误记录,对相同的错误记录(即文件名称和行号完全匹配)只记录一条,错误计数增加;(文件所在的目录不同,文件名和行号相同也要合并)

2.超过16个字符的文件名称,只记录文件的最后有效16个字符;(如果文件名不同,而只是文件名的后16个字符和行号相同,也不要合并)

3.输入的文件可能带路径,记录文件名称不能带路径

输入描述:

一行或多行字符串。每行包括带路径文件名称,行号,以空格隔开。

文件路径为windows格式

如:E:\V1R2\product\fpgadrive.c 1325

输出描述:

将所有的记录统计并将结果输出,格式:文件名代码行数数目,一个空格隔开,如: fpgadrive.c 1325 1

结果根据数目从多到少排序,数目相同的情况下,按照输入第一次出现顺序排序。

如果超过8条记录,则只输出前8条记录.

如果文件名的长度超过16个字符,则只输出后16个字符

输入例子:

E:\V1R2\product\fpgadrive.c 1325

输出例子:

fpgadrive.c 1325 1

以下是我写的c++代码,本地VS2013能正常输出,但是提交时总是报错,报错内容为:

运行错误:请检查是否存在数组、列表等越界非法访问,内存非法访问等情况

#include

#include

#include

#include

#include

using namespace std;

int main(void)

{

vector > fileName;

string tempFileName;

while (getline(cin, tempFileName))

{

if (tempFileName.empty())

{

break;

}

string::size_type indexOfDot = tempFileName.find(".c");

string::size_type indexOfXieXian = tempFileName.rfind("\\");

string::size_type isFind;

int tempIndex = -1;

if (indexOfXieXian!=string::npos)

{

tempFileName = tempFileName.substr(indexOfXieXian + 1);

}

for (int i = 0; i < fileName.size();i++)

{

if (fileName[i][0]==tempFileName)

{

tempIndex = i;

break;

}

}

if (tempIndex==-1)

{

vector temp;

temp.clear();

temp.push_back(tempFileName);

fileName.push_back(temp);

}

else

{

fileName[tempIndex].push_back(tempFileName);

}

}

vector count,tempCount,flag(fileName.size(),0);

count.clear();

tempCount.clear();

for (int i = 0; i < fileName.size();i++)

{

tempCount.push_back(fileName[i].size());

}

stable_sort(tempCount.begin(), tempCount.end());

for (int i = tempCount.size()-1; i >=0 ;i--)

{

count.push_back(tempCount.at(i));

}

for (int i = 0; (i < 8) && (i < count.size());i++)

{

for (int j = 0; j < fileName.size(); j++)

{

if ((count[i] == fileName[j].size())&&(flag[j]==0))

{

flag[j] = 1;

string::size_type tempIndexOfDot = fileName[j][0].find(".c");

if (tempIndexOfDot>14)

{

cout << fileName[j][0].substr(tempIndexOfDot - 14) << " " << count[i] << endl;

}

else

{

cout << fileName[j][0] << " " << count[i] << endl;

}

break;

}

}

}

//system("pause");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值