L1-072 刮刮彩票 (20 分)

L1-072 刮刮彩票 (20 分)

题目链接

题意

在这里插入图片描述

思路

  1. 要先利用二维数组输入3行3列给出0至9的数字,再将其求出总和,算出在二维数组中等于0的数字上的数字;
  2. 再依次输入查询坐标,输出当前查询坐标上的数字;
  3. 再依次判断要将哪一行上的数字相加,再算出总和依次判断

坑点

1.要先算出在二维数组中0上的数字

代码
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
int a[5][5];
int main()
{
	int m,sum=0;
	for(int i=1;i<=3;i++)//先3行3列给出0至9的数字
	{
		for(int j=1;j<=3;j++)
		{
			cin>>a[i][j];
			sum+=a[i][j];//为了求0位置的数
		}
	}
	m=45-sum;//算出0位置上的数字; 
	int x,y;//分别输入刮彩票数字的坐标; 
	for(int i=1;i<=3;i++)
	{
		cin>>x>>y;
		cout<<a[x][y]<<endl;//查询到刮出彩票的数字,就输出 
	}	
	int n;//查询的行数 
	cin>>n;
	int he=0;//求出哪一行上数字的总和; 
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			if(a[i][j]==0)
			{
				a[i][j]=m;//将求出的m赋值给a[i][j]上等于0的数 
			}
		}
	}
    //不同方向的和不同
	if(n==1)//再依次求出哪一行上的总和 
	{
		he=a[1][1]+a[1][2]+a[1][3];
	}
	if(n==2)
	{
		he=a[2][1]+a[2][2]+a[2][3];
	}
	if(n==3)
	{
		he=a[3][1]+a[3][2]+a[3][3];
	}
	if(n==4)
	{
		he=a[1][1]+a[2][1]+a[3][1];
	}
	if(n==5)
	{
		he=a[1][2]+a[2][2]+a[3][2];
	}
	if(n==6)
	{
		he=a[1][3]+a[2][3]+a[3][3];
	}
	if(n==7)
	{
		he=a[1][1]+a[2][2]+a[3][3];
	}
	if(n==8)
	{
		he=a[1][3]+a[2][2]+a[3][1];
	}
//	cout<<he;
    //对应金额
	if(he==6)
	{
		cout<<"10000"<<endl;
	}
	if(he==7||he==19)
	{
		cout<<"36"<<endl;
	}
	if(he==8)
	{
		cout<<"720"<<endl;
	}
	if(he==9)
	{
		cout<<"360"<<endl;
	}
	if(he==10)
	{
		cout<<"80"<<endl;
	}
	if(he==11)
	{
		cout<<"252"<<endl;
	}
	if(he==12)
	{
		cout<<"108"<<endl;
	}
	if(he==13||he==16)
	{
		cout<<"72"<<endl;
	}
	if(he==14)
	{
		cout<<"54"<<endl;
	}
	if(he==15||he==17)
	{
		cout<<"180"<<endl;
	}
	if(he==18)
	{
		cout<<"119"<<endl;
	}
	if(he==20)
	{
		cout<<"306"<<endl;
	}
	if(he==21)
	{
		cout<<"1080"<<endl;
	}
	if(he==22)
	{
		cout<<"144"<<endl;
	}
	if(he==23)
	{
		cout<<"1800"<<endl;
	}
	if(he==24)
	{
		cout<<"3600"<<endl;
	}
	return 0; 
} 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值