UVa_512 - Spreadsheet Tracking


 Spreadsheet Tracking 

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


Some spreadsheets allow users to mark collections of rows or columns fordeletion, so the entire collection can bedeleted at once. Some (unusual) spreadsheets allow users to mark collectionsof rows or columns for insertions too.Issuing an insertion command results in new rows or columns being insertedbefore each of the marked rows orcolumns. Suppose, for example, the user marks rows 1 and 5 of the spreadsheeton the left for deletion. Thespreadsheet 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, thespreadsheet shrinks to this.


$\searrow$12345
122482216
21819212225
32425672271
41612102258
53334362240

If the user marks rows 2, 3 and 5 for insertion, the spreadsheet grows tothe one on the left. If the user then markscolumn 3 for insertion, the spreadsheet grows to the one in the middle.Finally, if the user exchanges the contents ofcell (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 datain 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 thosespreadsheets, and queries about them. Eachspreadsheet definition begins with a pair of integers specifying its initialnumber 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 thedesired operations.


An operation to exchange the contents of cell (r1,c1) with the contentsof cell (r2,c2) is given by:


EX r1 c1r2 c2


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


<command> A x1 x2 $\dots$xA


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


The operations are followed by an integer which is the number of queries forthe spreadsheet. Each query consists ofpositive integersr and c, representing the row and column number of a cellin the original spreadsheet. For eachquery, your program must determine the current location of the data thatwas originally in cell (r,c). The end ofinput is indicated by a row consisting of a pair of zeros for the spreadsheetdimensions.

Output 

For each spreadsheet, your program must output its sequence number (startingat 1). For each query, your programmust output the original cell location followed by the final location ofthe data or the wordGONE if the contents ofthe 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 thespreadsheet 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)

 

题意:

有一个r行c列的电子表格,对其进行n个操作。操作类型分为5种:

1. 删除行 2. 删除列 3. 插入行 4. 插入列 5. 交换两个元素位置

输入初始查找位置,输出经过n个操作后,变更的位置

解题:

1. 可以直接模拟,但是需要开很多额外空间;

2. 先将n个操作存起来,然后对每个查询分别执行这个n个操作,输出变更后位置。这样节约空间,也很简单方便

注意:

1. 在执行DR,DC,IR,IC操作时,必须先将位置(x,y)保存下,见代码,即:xx = x, yy = y;(因为这四个操作是基于初始的位置x,y进行的)

2. 不同的测试用例用空行隔开,最后一个用例不能有空行,开始Wrong answer就因为最后多输出一空行

代码如下:

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;

const int MAX = 10000;
int r,c,n;
struct cmd
{
    string s;
    int A,a[20];
    int r1,c1,r2,c2;
}cmds[MAX];

void save(string str, int i)
{
    int A;
    if(str!="EX"){
        cin>>A;
        cmds[i].s = str; cmds[i].A = A;
        for(int j=0;j<A;j++) cin>>cmds[i].a[j];
    }
    else if(str=="EX"){
        cmds[i].s = str;
        cin>>cmds[i].r1>>cmds[i].c1>>cmds[i].r2>>cmds[i].c2;
    }
}

bool solve(int& x, int& y)
{
    int xx,yy;
    for(int i=0;i<n;i++)
    {
        if(cmds[i].s=="DR"){
            xx = x; yy = y;
            for(int j=0;j<cmds[i].A;j++){
                if(cmds[i].a[j]<xx) { x--; }
                else if(cmds[i].a[j]==xx) { return false;}
            }
        }
        else if(cmds[i].s=="DC"){
            xx = x; yy = y;
            for(int j=0;j<cmds[i].A;j++){
                if(cmds[i].a[j]<yy)  {  y--;}
                else if(cmds[i].a[j]==yy) { return false;}
            }
        }
        else if(cmds[i].s=="IC"){
            xx = x; yy = y;
            for(int j=0;j<cmds[i].A;j++){
                if(cmds[i].a[j]<=yy) y++;
            }
        }
        else if(cmds[i].s=="IR"){
            xx = x; yy = y;
            for(int j=0;j<cmds[i].A;j++){
                if(cmds[i].a[j]<=xx)  x++;
            }
        }
        else if(cmds[i].s=="EX"){
            if(x==cmds[i].r1&&y==cmds[i].c1) { x = cmds[i].r2; y =cmds[i].c2;}
            else if(x==cmds[i].r2&&y==cmds[i].c2) { x = cmds[i].r1; y =cmds[i].c1;}
        }
    }
    return true;
}

int main()
{
    //freopen("512.txt","r",stdin);
    //freopen("512ans.txt","w",stdout);
    int icase = 0;
    while(cin>>r>>c)
    {
        if(r==0&&c==0) break;
        cin>>n;
        if(icase>0) cout<<endl;
        for(int i=0;i<n;i++)
        {
            string str; cin>>str;
            save(str,i);
        }
        cout<<"Spreadsheet #"<<++icase<<endl;
        int q; cin>>q;
        while(q--)
        {
            int x,y,xx,yy;
            cin>>x>>y; xx = x; yy = y;
            if(solve(x,y)) printf("Cell data in (%d,%d) moved to (%d,%d)\n",xx,yy,x,y);
            else printf("Cell data in (%d,%d) GONE\n",xx,yy);
        }
    }
    return 0;
}

 

void CDemoView::OnSendmessagePmctlgetfile() // // Display information about the current file. { if (! Validate()) { return; } PAN_CtlFileInfo fi; if (! SendMsg(PM_CTLGETFILE, 0, (LPARAM)(PAN_CtlFileInfo * ) &fi)) { return; } m_pWndOut->SendToOutput("PM_CTLGETFILE:\r"); switch (fi.type) { case PAN_RasterFile : m_pWndOut->SendToOutput("type: RASTER FILE"); break; case PAN_VectorFile : m_pWndOut->SendToOutput("type: VECTOR FILE"); break; case PAN_DatabaseFile : m_pWndOut->SendToOutput("type: DATABASE FILE"); break; case PAN_SpreadsheetFile : m_pWndOut->SendToOutput("type: SPREADSHEET FILE"); break; case PAN_DocumentFile : m_pWndOut->SendToOutput("type: DOCUMENT FILE"); break; case PAN_ArchiveFile : m_pWndOut->SendToOutput("type: ARCHIVE FILE"); break; } /* switch */ m_pWndOut->SendToOutput("name: %s", fi.name); m_pWndOut->SendToOutput("size: %ld", fi.size); time_t currentDate = fi.date; m_pWndOut->SendToOutput("date: %s", ctime(&currentDate)); m_pWndOut->SendToOutput("desc: %s", fi.desc); // display the dimensions PAN_CtlRange* rg = &fi.dimensions; switch (fi.type) { case PAN_VectorFile: m_pWndOut->SendToOutput("dim : %.2lf x %.2lf x %.2lf\r", rg->max.x - rg->min.x, rg->max.y - rg->min.y, rg->max.z - rg->min.z); break; case PAN_RasterFile: m_pWndOut->SendToOutput("dim : %.2lf x %.2lf\r", rg->max.x - rg->min.x, rg->max.y - rg->min.y); break; default: m_pWndOut->SendToOutput("dim : %.2lf x %.2lf\r", rg->max.x - rg->min.x , rg->max.y - rg->min.y); } m_pWndOut->SendToOutput("colr: %d (bits)", fi.colorDepth); m_pWndOut->SendToOutput("nbPg: %d", fi.nPages); if ( fi.type == PAN_RasterFile ) { m_pWndOut->SendToOutput("tiles: %d x %d", fi.tilex, fi.tiley); } if ( fi.ins.offset.x !=0 || fi.ins.offset.y !=0 || fi.ins.offset.z != 0 || fi.ins.scale.x !=0 || fi.ins.scale.y !=0 || fi.ins.scale.z != 0 ) { m_pWndOut->SendToOutput("Insertion data:\n"); m_pWndOut->SendToOutput(" Point: (%.2lf, %.2lf, %.2lf)", fi.ins.offset.x, fi.ins.offset.y, fi.ins.offset.z); m_pWndOut->SendToOutput(" Scaling: (%.2lf, %.2lf, %.2lf)", fi.ins.scale.x, fi.ins.scale.y, fi.ins.scale.z); m_pWndOut->SendToOutput(" Resolution: (%.2lf, %.2lf, %.2lf)", fi.ins.dpi.x, fi.ins.dpi.y, fi.ins.dpi.z); m_pWndOut->SendToOutput(" Rotation: %.2lf radians", fi.ins.rot); } }
最新发布
07-16
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值