一、题目
二、解题思路
- 将输入的 0 修改为对应的数字;
- 按照指定的方向将三个数字相加,输出此数字对应的金币数。
三、代码
#include<iostream>
using namespace std;
int main()
{
int a[5][5],b[15],I,J;
for(int i=0;i<=9;i++)
{
b[i]=0;
}
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
cin>>a[i][j];
b[a[i][j]]=1;
if(a[i][j]==0)
{
I=i;
J=j;
}
}
}
for(int i=0;i<=9;i++)
{
if(b[i]==0)
{
a[I][J]=i;
}
}
for(int i=0;i<3;i++)
{
int x,y;
cin>>x>>y;
cout<<a[x][y]<<endl;
}
int x;
int money[30]={0,0,0,0,0,0,10000,36,720,360,80,252,108,72,54,180,72,180,119,36,306,1080,144,1800,3600};
cin>>x;
if(x==1)
{
cout<<money[a[1][1]+a[1][2]+a[1][3]];
}
else if(x==2)
{
cout<<money[a[2][1]+a[2][2]+a[2][3]];
}
else if(x==3)
{
cout<<money[a[3][1]+a[3][2]+a[3][3]];
}
else if(x==4)
{
cout<<money[a[1][1]+a[2][1]+a[3][1]];
}
else if(x==5)
{
cout<<money[a[1][2]+a[2][2]+a[3][2]];
}
else if(x==6)
{
cout<<money[a[1][3]+a[2][3]+a[3][3]];
}
else if(x==7)
{
cout<<money[a[1][1]+a[2][2]+a[3][3]];
}
else if(x==8)
{
cout<<money[a[1][3]+a[2][2]+a[3][1]];
}
return 0;
}
四、总结
按照指定的方向将三个数字相加时,注意不要把下标写错。