Spreadsheet Tracking

This blog discusses spreadsheet management, focusing on operations like cell manipulations, row and column insertions/deletions, and content exchanges. It also presents a task to develop tracking software that can determine the final positions of data after such operations, given specific input commands and queries." 122761376,11743574,Android开发者求职秘籍:如何打造吸引大厂的简历,"['移动开发', 'Android', '求职攻略']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Data in spreadsheets are stored in cells, which are organized in rows (r) and columns (c). Some operations on spreadsheets can be applied to single cells (r,c), while others can be applied to entire rows or columns. Typical cell operations include inserting and deleting rows or columns and exchanging cell contents.


Some spreadsheets allow users to mark collections of rows or columns for deletion, so the entire collection can be deleted at once. Some (unusual) spreadsheets allow users to mark collections of rows or columns for insertions too. Issuing an insertion command results in new rows or columns being inserted before each of the marked rows or columns. Suppose, for example, the user marks rows 1 and 5 of the spreadsheet on the left for deletion. The spreadsheet then shrinks to the one on the right.


$\textstyle \parbox{.5\textwidth}{\begin{center}\begin{tabular}{r\vert r\vert ......4 & 35 & 36 & 22 & 38 & 39 & 40 & 41\\ \cline{2-10}\end{tabular}\end{center}}$$\textstyle \parbox{.49\textwidth}{\begin{center}\begin{tabular}{r\vert r\vert......4 & 35 & 36 & 22 & 38 & 39 & 40 & 41\\ \cline{2-10}\end{tabular}\end{center}}$


If the user subsequently marks columns 3, 6, 7, and 9 for deletion, the spreadsheet shrinks to this.


$\searrow$12345
122482216
21819212225
32425672271
41612102258
53334362240

If the user marks rows 2, 3 and 5 for insertion, the spreadsheet grows to the one on the left. If the user then marks column 3 for insertion, the spreadsheet grows to the one in the middle. Finally, if the user exchanges the contents of cell (1,2) and cell (6,5), the spreadsheet looks like the one on the right.


$\textstyle \parbox{.33\textwidth}{\begin{center}\begin{tabular}{r\vert r\vert......cline{2-6}8 & 33 & 34 & 36 & 22 & 40\\ \cline{2-6}\end{tabular}\end{center}}$$\textstyle \parbox{.33\textwidth}{\begin{center}\begin{tabular}{r\vert r\vert......ine{2-7}8 & 33 & 34 & & 36 & 22 & 40\\ \cline{2-7}\end{tabular}\end{center}}$$\textstyle \parbox{.32\textwidth}{\begin{center}\begin{tabular}{r\vert r\vert......ine{2-7}8 & 33 & 34 & & 36 & 22 & 40\\ \cline{2-7}\end{tabular}\end{center}}$


You must write tracking software that determines the final location of data in spreadsheets that result from row, column, and exchange operations similar to the ones illustrated here.

Input 

The input consists of a sequence of spreadsheets, operations on those spreadsheets, and queries about them. Each spreadsheet definition begins with a pair of integers specifying its initial number of rows ( r ) and columns ( c ), followed by an integer specifying the number ( n ) of spreadsheet operations. Row and column labeling begins with 1. The maximum number of rows or columns of each spreadsheet is limited to 50. The following n lines specify the desired operations.


An operation to exchange the contents of cell (r1c1) with the contents of cell (r2c2) is given by:


EX r1 c1 r2 c2


The four insert and delete commands--DC (delete columns), DR (delete rows), IC (insert columns), and IR(insert rows) are given by:


<commandA x1 x2 $\dots$ xA


where <command> is one of the four commands; A is a positive integer less than 10, and $x_1, \dots, x_A$ are the labels of the columns or rows to be deleted or inserted before. For each insert and delete command, the order of the rows or columns in the command has no significance. Within a single delete or insert command, labels will be unique.


The operations are followed by an integer which is the number of queries for the spreadsheet. Each query consists of positive integers r and c, representing the row and column number of a cell in the original spreadsheet. For each query, your program must determine the current location of the data that was originally in cell (rc). The end of input is indicated by a row consisting of a pair of zeros for the spreadsheet dimensions.

Output 

For each spreadsheet, your program must output its sequence number (starting at 1). For each query, your program must output the original cell location followed by the final location of the data or the word  GONE  if the contents of the original cell location were destroyed as a result of the operations. Separate output from different spreadsheets with a blank line.


The data file will not contain a sequence of commands that will cause the spreadsheet to exceed the maximum size.

Sample Input 

7 9
5
DR   2  1 5
DC  4  3 6 7 9
IC  1  3
IR  2  2 4
EX 1 2 6 5
4
4 8
5 5
7 8
6 5
0 0

Sample Output 

Spreadsheet #1
Cell data in (4,8) moved to (4,6)
Cell data in (5,5) GONE
Cell data in (7,8) moved to (7,6)
Cell data in (6,5) moved to (1,2)
就是类似于excel的操作,问插入删除之后,原来在ij处到了哪里。
一开始的想法就是用一个数字标记原来,然后每次改变都模拟,最后就得到了最后的图表位置由原来的位置得到,再打表,最后查询,但是错了,原因在于如果删除2,4行,那么删了2之后,下一个删的就变成了3行,即原来的4行,用了一个偏移值,但是就是错,后来发现,并不是从小到大输入,于是先一口气输入之后再排序变化,a了。
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int ans[20];
struct  Node{
	int x;
	int y;
}node[55][55];
struct Dp{
	int x;
	int y;
}dp[55][55];
int max(int a, int b)
{
	return a > b ? a : b;
}
void out(int x, int y)
{
	int i, j;
	for (i = 1; i <= x; i++)
	{
		for (j = 1; j <= y; j++)
			cout << node[i][j].x << node[i][j].y << " ";
		cout << endl;
	}
}
int main()
{
	int i, j, m, n, t, r, c, temp, k;
	char a[2];
	int p = 1;
	Node sample;
	sample.x = 0; sample.y = 0;
	while (scanf("%d%d", &r, &c) != EOF)
	{
		if (!r || !c)break;
		int tempr, tempc;
		tempr = r; tempc = c;
		cin >> n;
		for (i = 1; i <= 54;i++)
		for (j = 1; j <= 54; j++)
		{
			if (i <= r&&j <= c)
			{
				node[i][j].x = i;
				node[i][j].y = j;
			}
			else
			{
				node[i][j].x = 0;
				node[i][j].y = 0;
			}
		}
		while (n--)
		{
			scanf("%s", a);
			if (a[0] == 'D'&&a[1] == 'R')
			{
				cin >> temp;
				for (i = 1; i <= temp; i++)
					cin >> ans[i];
				sort(ans + 1, ans + 1 + temp);
				for (k = 1; k <= temp; k++)
				{
					ans[k] = ans[k] - k + 1;
					for (i = ans[k]; i < r; i++)
					{
						for (j = 1; j <= c; j++)
							node[i][j] = node[i + 1][j];
					}
					for (i = 1; i <= c; i++)
						node[r][i] = sample;
					/*out(r, c);*/
					r--;
				}
			}
			else if (a[0] == 'D'&&a[1] == 'C')
			{
				cin >> temp;
				for (i = 1; i <= temp; i++)
					cin >> ans[i];
				sort(ans + 1, ans + 1 + temp);
				for (k = 1; k <= temp; k++)
				{
					ans[k] = ans[k] - k + 1;
					for (j = ans[k]; j < c; j++)
					{
						for (i = 1; i <= r; i++)
							node[i][j] = node[i][j + 1];
					}
					for (i = 1; i <= r; i++)
						node[i][c] = sample;
					/*out(r, c);*/
					c--;
				}
			}
			else if (a[0] == 'I'&&a[1] == 'C')
			{
				cin >> temp;
				for (i = 1; i <= temp; i++)
					cin >> ans[i];
				sort(ans + 1, ans + 1 + temp);
				for (k = 1; k <= temp; k++)
				{
					ans[k] = ans[k] + k - 1;
					for (j = c + 1; j > ans[k]; j--)
					{
						for (i = 1; i <= r; i++)
							node[i][j] = node[i][j - 1];
					}
					for (i = 1; i <= r; i++)
						node[i][ans[k]] = sample;
					c++;
				/*	out(r, c);*/
				}
			}
			else if (a[0] == 'I'&&a[1] == 'R')
			{
				cin >> temp;
				for (i = 1; i <= temp; i++)
					cin >> ans[i];
				sort(ans + 1, ans + 1 + temp);
				for (k = 1; k <= temp; k++)
				{
					ans[k] = ans[k] + k - 1;
					for (i = r + 1; i > ans[k]; i--)
					{
						for (j = 1; j <= c; j++)
							node[i][j] = node[i - 1][j];
					}
					for (j = 1; j <= c; j++)
						node[ans[k]][j] = sample;
					r++;
					/*out(r, c);*/
				}
			}
			else if (a[0] == 'E'&&a[1] == 'X')
			{
				int temp1, temp2, temp3, temp4;
				Node temp5;
				cin >> temp1 >> temp2 >> temp3 >> temp4;
				temp5 = node[temp1][temp2];
				node[temp1][temp2] = node[temp3][temp4];
				node[temp3][temp4] = temp5;
			}
		}
		for (i = 0; i <= 54;i++)
		for (j = 0; j <= 54; j++)
		{
			dp[i][j].x = dp[i][j].y = 0;
		}
		for (i = 1; i <= r; i++)
		for (j = 1; j <= c; j++)
		{
			int tempx, tempy;
			tempx = node[i][j].x;
			tempy = node[i][j].y;
			dp[tempx][tempy].x = i;
			dp[tempx][tempy].y = j;
		}
		if (p != 1)
			cout << endl;
		cout << "Spreadsheet #" << p << endl;
		p++;
		cin >> n;
		while (n--)
		{
			int x, y;
			cin >> x >> y;
			if (dp[x][y].x == 0 && dp[x][y].y == 0)
				cout << "Cell data in (" << x << "," << y << ") GONE" << endl;
			else
				cout << "Cell data in (" << x << "," << y << ") moved to (" << dp[x][y].x << "," << dp[x][y].y << ")" << endl;
		}
	}
	return 0;
}

看了网上别人说的先保存指令,然后根据输入的坐标进行计算,然而我并不会保存指令,总觉得麻烦,不过也是一个好思路。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值