#14505: 錯誤訊息 不太了解


luckyanthonyan@gmail.com (S P)

學校 : 國立嘉義女子高級中學
編號 : 69594
來源 : [39.12.158.80]
最後登入時間 :
2018-03-03 21:08:37
b291. 生態調查 -- 103學年度板橋高中校內資訊學科能力競賽(一) | From: [27.247.94.94] | 發表日期 : 2018-07-21 14:18

編譯後50分 

/*

系統呼叫了 abort 函式!
terminate called after throwing an instance of 'St9bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)
*/
//跑出以上文字
//以下是我程式碼 ,請大大幫忙看看謝謝!
#include<bits/stdc++.h>
#define ED end()
#define BG begin()
#define PB push_back
#define MP make_pair
#define ll long long
#define pii pair<int,int>
#define Size size()
//#define test_
using namespace std;
const int MAXN = 1010;
int main(){
int times; cin>>times;
map< string, map<string,int> > mp;
string animal,place;
int num;
string setp[1010];
string seta[1010];
int m=0,n=0;
for(int i=0;i<times;i++){
cin>>animal>>num>>place;
if(mp[place][animal]) mp[place][animal]+=num;
else mp[place][animal]=num;
bool chk=false;
for(int j=0;j<m;j++) if(setp[j]==place) chk=true;
if(!chk) setp[m]=place,m++;
chk=false;
for(int j=0;j<n;j++) if(seta[j]==animal) chk=true;
if(!chk) seta[n]=animal,n++;
chk=false;
}

for(int i=0;i<m;i++){
cout<<setp[i]<<" : ";
int cnt=0;
for(int j=0;j<n;j++){
if(mp[setp[i]][seta[j]]>0){
if(cnt>0) cout<<", ";
cout<<seta[j]<<" "<<mp[setp[i]][seta[j]];
cnt++;
}
}
cout<<'\n';
}
}

 
#19892: Re:錯誤訊息 不太了解


tico88612 (Kagamine Rin)

學校 : 花蓮縣慈濟大學附中
編號 : 55080
來源 : [1.200.245.21]
最後登入時間 :
2023-05-13 08:23:59
b291. 生態調查 -- 103學年度板橋高中校內資訊學科能力競賽(一) | From: [114.136.65.63] | 發表日期 : 2019-11-07 12:13

編譯後50分 

/*

系統呼叫了 abort 函式!
terminate called after throwing an instance of 'St9bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)
*/
//跑出以上文字
//以下是我程式碼 ,請大大幫忙看看謝謝!
#include<bits/stdc++.h>
#define ED end()
#define BG begin()
#define PB push_back
#define MP make_pair
#define ll long long
#define pii pair<int,int>
#define Size size()
//#define test_
using namespace std;
const int MAXN = 1010;
int main(){
int times; cin>>times;
map< string, map<string,int> > mp;
string animal,place;
int num;
string setp[1010];
string seta[1010];
int m=0,n=0;
for(int i=0;i<times;i++){
cin>>animal>>num>>place;
if(mp[place][animal]) mp[place][animal]+=num;
else mp[place][animal]=num;
bool chk=false;
for(int j=0;j<m;j++) if(setp[j]==place) chk=true;
if(!chk) setp[m]=place,m++;
chk=false;
for(int j=0;j<n;j++) if(seta[j]==animal) chk=true;
if(!chk) seta[n]=animal,n++;
chk=false;
}

for(int i=0;i<m;i++){
cout<<setp[i]<<" : ";
int cnt=0;
for(int j=0;j<n;j++){
if(mp[setp[i]][seta[j]]>0){
if(cnt>0) cout<<", ";
cout<<seta[j]<<" "<<mp[setp[i]][seta[j]];
cnt++;
}
}
cout<<'\n';
}
}

最好先用 find 來檢查該 key 有沒有存在

不然會吃 St9bad_alloc 錯誤

 
ZeroJudge Forum