UVa 512 - Spreadsheet Tracking

#include <iostream>
#include <cctype>
#include <string>
using namespace std;

int main()
{
    int m, n, count = 0;
    cin >> m;
    while (cin >> n)
    {
        cout << "Spreadsheet #" << ++count << endl;
        int action, q, row, col;
        int target[100][100];
        string act[100];

        input action part
        cin >> action;
        for (int i = 0; i < action; i++)
        {
            cin >> act[i]; // action
            if (act[i] == "EX")
            {
                for (int j = 0; j < 4; j++)
                {
                    cin >> target[i][j];
                }
            }
            else
            {
                cin >> target[i][0]; // target number
                for (int j = 0; j < target[i][0]; j++)
                {
                    cin >> target[i][j + 1];
                }
            }
        }

        search part
        cin >> q;
        for (int ii = 0; ii < q; ii++)
        {
            int row1, col1;
            cin >> row1 >> col1;
            row = row1;
            col = col1;
            for (int i = 0; i < action; i++)
            {
                if (act[i] == "EX")
                {
                    if (target[i][0] == row && target[i][1] == col)
                    {
                        row = target[i][2];
                        col = target[i][3];
                    }
                    else if (target[i][2] == row && target[i][3] == col)
                    {
                        row = target[i][0];
                        col = target[i][1];
                    }
                }
                else if (act[i] == "DR")
                {
                    if (row)
                    {
                        int sum = 0;
                        for (int j = 1; j <= target[i][0]; j++)
                        {
                            if (target[i][j] < row)
                                sum++;
                            else if (target[i][j] == row)
                            {
                                row = 0;
                                col = 0;
                                break;
                            }
                        }
                        if (row)
                            row -= sum;
                    }
                }
                else if (act[i] == "IR")
                {
                    if (row)
                    {
                        int sum = 0;
                        for (int j = 1; j <= target[i][0]; j++)
                        {
                            if (target[i][j] <= row)
                                sum++;
                        }
                        row += sum;
                    }
                }
                else if (act[i] == "DC")
                {
                    if (col)
                    {
                        int sum = 0;
                        for (int j = 1; j <= target[i][0]; j++)
                        {
                            if (target[i][j] < col)
                                sum++;
                            else if (target[i][j] == col)
                            {
                                col = 0;
                                row = 0;
                                break;
                            }
                        }
                        if (col)
                            col -= sum;
                    }
                }
                else if (act[i] == "IC")
                {
                    if (col)
                    {
                        int sum = 0;
                        for (int j = 1; j <= target[i][0]; j++)
                        {
                            if (target[i][j] <= col)
                                sum++;
                        }
                        col += sum;
                    }
                }
            }
            if (row)
            {
                cout << "Cell data in (" << row1 << "," << col1 << ") moved to (" << row << "," << col << ")" << endl;
            }
            else
            {
                cout << "Cell data in (" << row1 << "," << col1 << ") GONE" << endl;
            }
        }
        cin >> m;
        if (m)
            cout << endl;
        else
            break;
    }
    return 0;
}

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值