L1-072 Scratch the lottery ticket (20 points)

"Scratch the lottery" is a small game in an online game. as the picture shows:

-362960_55cb6a89bf693.png

Each time a game player will get a lottery ticket, there will be 9 numbers on it, from number 1 to number 9, the numbers are not repeated, and they are arranged on the lottery in the form of a 3×3 "nine square grid".

At the beginning of the game, you can see the numbers in one position, but the numbers in other positions are not visible. You can choose to scratch the numbers in three positions so that the player can see the numbers in the four positions. Finally, the player chooses a direction from 8 directions, 3 horizontal, 3 vertical, and 2 oblique. The sum of the three numbers in the direction can be redeemed according to the following table to obtain the corresponding amount of gold coins.

数字合计	获得金币	数字合计	获得金币
6	10,000	16	72
7	36	17	180
8	720	18	119
9	360	19	36
10	80	20	306
11	252	21	1,080
12	108	22	144
13	72	23	1,800
14	54	24	3,600
15	180		

Now please write a simulation program to simulate the player's game process.

Input format:
Input the first part to give a valid lottery ticket, that is, give numbers from 0 to 9 in 3 rows and 3 columns. 0 means that the number at this position is initially visible, not the number on the lottery ticket is 0.

The second part gives the three positions of the player's scratching, divided into three rows. Each row gives the row number and column number of the player's scratching position according to the format xy (the position of the upper left corner is defined in the title as the first row and the first row. 1 column.). The data guarantees that players will not repeatedly scratch the numbers that have been scratched.

The last part gives the direction the player chooses, that is, an integer: 1 to 3 indicate the first, second, and third horizontal rows, 4 to 6 indicate the first, second, and third vertical columns, 7, 8 respectively represent the main diagonal from top left to bottom right and the sub diagonal from top right to bottom left.

Output format:
For each scraping operation, output the numbers that the player can see in one line. Finally, for the selected direction, output the number of gold coins obtained by the player in a row.

Input example:
1 2 3
4 5 6
7 8 0
1 1
2 2
2 3
7
Output example:
1
5
6
180
Note: 0 means that the number at this position can be seen initially, not on the lottery ticket The number is 0.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int gold[25]={
    
    0,0,0,0,0,0,10000,36,720,360,80,252,108,72,54,180,72,180,119,36,309,1080,144,1800,3600};
int main()
{
    
    
	int g[10][10],b[10],tx,ty;
	for(int i=1;i<=3;i++)
	 for(int j=1;j<=3;j++)
	 {
    
    
	 	cin>>g[i][j];
	 	b[g[i][j]]=1;
	 	if(g[i][j]==0) tx=i,ty=j;
	 }
	for(int i=1;i<=9;i++)
	 if(b[i]==0)
	 {
    
    
	 	g[tx][ty]=i;break;
	 }
	for(int i=1;i<=3;i++)
	{
    
    
		cin>>tx>>ty;
		cout<<g[tx][ty]<<endl;
	}
	cin>>tx;ty=0;
	if(tx>=1&&tx<=3)
	{
    
    
	 for(int i=1;i<=3;i++)
	  ty+=g[tx][i];	
	}
	else if(tx<=6)
	{
    
    
		for(int i=1;i<=3;i++)
		 ty+=g[i][tx-3];
	}
	else if(tx==7) ty=g[1][1]+g[2][2]+g[3][3];
	else ty=g[3][1]+g[2][2]+g[1][3];
	cout<<gold[ty];
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_43540515/article/details/112979274