#include <iostream>
using namespace std;
int main()
{
int n;
string a[12]={"豬","鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗"};
while(cin>>n)
{
if(n>0)
{
cout<<a[n%12]<<endl;
}
else
{
cout<<a[(n+108)%12+1]<<endl;
}
}
return 0;
}
#include
using namespace std;
int main()
{
int n;
string a[12]={"豬","鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗"};
while(cin>>n)
{
if(n>0)
{
cout<<a[n%12]<<endl;
}
else
{
cout<<a[(n+108)%12+1]<<endl;
}
}
return 0;
}
(n+108)%12+1
有機會是12
超出陣列範圍
#include
using namespace std;
int main()
{
int n;
string a[12]={"豬","鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗"};
while(cin>>n)
{
if(n>0)
{
cout<<a[n%12]<<endl;
}
else
{
cout<<a[(n+108)%12+1]<<endl;
}
}
return 0;
}
n<0內是為了把n調成正數
#include
using namespace std;
int main()
{
int n;
string a[12]={"豬","鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗"};
while(cin>>n)
{
if(n>0)
{
cout<<a[n%12]<<endl;
}
else
{
cout<<a[(n+108)%12+1]<<endl;
}
}
return 0;
}
(n+108)%12+1
有機會是12
超出陣列範圍
(n+108)%12-11也不行(<0)
#include
using namespace std;
int main()
{
int n;
string a[12]={"豬","鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗"};
while(cin>>n)
{
if(n>0)
{
cout<<a[n%12]<<endl;
}
else
{
cout<<a[(n+108)%12+1]<<endl;
}
}
return 0;
}
(n+108)%12+1
有機會是12
超出陣列範圍
(n+108)%12-11也不行(<0)
那就+109 ~
#include
using namespace std;
int main()
{
int n;
string a[12]={"豬","鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗"};
while(cin>>n)
{
if(n>0)
{
cout<<a[n%12]<<endl;
}
else
{
cout<<a[(n+108)%12+1]<<endl;
}
}
return 0;
}
(n+108)%12+1
有機會是12
超出陣列範圍
(n+108)%12-11也不行(<0)
那就+109 ~
(n+109)%12
#include
using namespace std;
int main()
{
int n;
string a[12]={"豬","鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗"};
while(cin>>n)
{
if(n>0)
{
cout<<a[n%12]<<endl;
}
else
{
cout<<a[(n+108)%12+1]<<endl;
}
}
return 0;
}
(n+108)%12+1
有機會是12
超出陣列範圍
(n+108)%12-11也不行(<0)
那就+109 ~
(n+109)%12
其實多宣告陣列a[12]=豬也可以