輸出檔大小超過規定上限 !! File size limit exceeded (core dumped)
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int number;
string a[12]={"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
while(cin>>number){
if(number>0) cout<<a[number%12-1]<<endl;
else if(number<0){
number=abs(number);
cout<<a[12-number%12]<<endl;
}
}
}
想請問有大神知道這原因嗎,謝謝
cout<<a[12-number%12]<<endl;
這行有問題,如果 n%12=0
就超過 array 索引了。
cout<<a[12-number%12]<<endl;
這行有問題,如果 n%12=0
就超過 array 索引了。