【发布时间】:2021-08-05 03:54:31
【问题描述】:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
cin>>n;
map<string,int>m;
string name;
int choice, marks;
while(n>0)
{
cin>>choice>>name;
if(choice==1)
{
cin>>marks;
map<string,int>::iterator itr=m.find(name);
if(itr==m.end())
{
m.insert(make_pair(name,marks));
}
else{
itr->second=itr->second+marks;
}
}
else if(choice==2)
{
map<string,int>::iterator itr=m.find(name);
itr->second=0;
}
else if(choice==3){
map<string,int>::iterator itr=m.find(name);
cout<<itr->second<<endl;
}
n--;
}
return 0;
}
- 从解决方案中读取符号...完成。
[新 LWP 144748] [启用使用 libthread_db 进行线程调试]
使用主机 libthread_db 库“/lib/x86_64-linux-gnu/libthread_db.so.1”。 核心是由`./Solution'生成的。
程序以 SIGSEGV 信号终止,分段错误。 #0 0x00007f4200000000 在 ?? ()
要启用此文件的执行,请添加 添加自动加载安全路径 /usr/local/lib64/libstdc++.so.6.0.25-gdb.py 行到您的配置文件“//.gdbinit”。
要完全禁用此安全保护,请添加 设置自动加载安全路径 / 行到您的配置文件“//.gdbinit”。
有关此安全保护的更多信息,请参阅 GDB 手册中的“自动加载安全路径”部分。例如,从 shell 运行: info "(gdb)自动加载安全路径"*
【问题讨论】:
-
你给你的程序提供了什么导致这个崩溃的输入?请编辑您的问题以添加此信息。
-
哪里崩溃了?在什么输入上?
-
When choice is 3 you have:
cout<<itr->second<<endl;what happens if name was not found?你假设它总是被找到。选择 2 时同样的问题。
标签: c++