請問出題者
測資是不是有負數啊==
#include <string>
#include <iostream>
using namespace std;
int main(){
long long int year;
string str[12]={"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
while(cin >> year)
cout << str[(year + 11) % 12] << endl;
}
不然這樣應該..........還是我寫錯?
是的~
題目中也有說「民國年份 -100 ~ 107」, (負100~正107)
本題的測資中也確實有負數沒錯唷~
以上希望有幫助到你~ OwO
是的~
題目中也有說「民國年份 -100 ~ 107」, (負100~正107)
本題的測資中也確實有負數沒錯唷~
以上希望有幫助到你~ OwO
#include <string>
#include <iostream>
using namespace std;
int main(){
long long int year;
string str[12]={"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
while(cin >> year){
if(year < 0) year = year + 109; //因為民國沒有0年 所以如果-1年的話要處理
cout << str[(year + 11) % 12] << endl;
}
}
是的~
題目中也有說「民國年份 -100 ~ 107」, (負100~正107)
本題的測資中也確實有負數沒錯唷~
以上希望有幫助到你~ OwO
#include
#include
using namespace std;
int main(){
long long int year;
string str[12]={"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
while(cin >> year){
if(year < 0) year = year + 109; //因為民國沒有0年 所以如果-1年的話要處理
cout << str[(year + 11) % 12] << endl;
}
}
遇到負數,就把陣列調整一下,反過來看。 3Q