大神求解
#include <iostream>
#include <string>
using namespace std;
int main(){
string a,b,divs,rome="MMMDCCCDMLXXXLCVIIIVX",strarr[4][10]={{"","M","MM","MMM","","","","","",""},{"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"},{"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"},{"","I","II","III","IV","V","VI","VII","VIII","IX"}};
int aptr,bptr,c,d,div,arr[21]={1000,1000,1000,500,100,100,100,300,800,50,10,10,10,30,80,5,1,1,1,3,8};
while(cin >> a >> b){
c=d=aptr=bptr=0;
for(int i=0;i<21||aptr<a.size();i++){
if (a[aptr]==rome[i])
c+=arr[i],aptr++;
}
for(int i=0;i<21||bptr<b.size();i++){
if (b[bptr]==rome[i])
d+=arr[i],bptr++;
}
div=abs(c-d);
if (!div)
cout << "ZERO\n";
else {
divs=to_string(div);
for(int i=0;i<4;i++){
divs+=strarr[i][divs[0]-48];
divs.erase(divs.begin());
}
cout << divs << "\n";
}
}
}
現在變成
系統呼叫了 abort 函式! terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)
了
現在變成
#0: 100% RE (SIGABRT)
系統呼叫了 abort 函式! terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)了
沒事 只是我腦殘而已
Accept