L1-072 刮刮彩票(20 分)

一、题目

二、解题思路

  1. 将输入的 0 修改为对应的数字;
  2. 按照指定的方向将三个数字相加,输出此数字对应的金币数。

三、代码

#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;
}

四、总结

        按照指定的方向将三个数字相加时,注意不要把下标写错。

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值