512 - Spreadsheet Tracking

题目链接:点击打开链接

#include <stdio.h>  
#include <string.h>  
#include <time.h>  
#define maxn 10000  
  
struct opera{  
    char ope_1[10];  
    int ope_2[10];  
}opera[maxn];  
int ope(int &x1,int &y1,int n1)  
{  
    for(int i=0;i<n1;i++)  
    {  
        int dr=0;  
        int dc=0;  
        if(opera[i].ope_1[0]=='D')  
           {  
            if(opera[i].ope_1[1]=='R')  
                for(int l=1;l<=opera[i].ope_2[0];l++)  
                {  
                    if(x1==opera[i].ope_2[l])  
                       {  
                        return 0;  
                        //printf("@2:%d\n",x1);  
                       }  
                    else if(x1>opera[i].ope_2[l])  
                        dr--;  
                        //printf("@3:%d%d\n",x1,y1);  
                }  
  
            else  
                for(int l=1;l<=opera[i].ope_2[0];l++)  
                {  
                    if(y1==opera[i].ope_2[l])  
                        return 0;  
                    else if(y1>opera[i].ope_2[l])  
                        dc--;  
                }  
  
           }  
        else if(opera[i].ope_1[0]=='I')  
            {  
            if(opera[i].ope_1[1]=='R')  
                for(int l=1;l<=opera[i].ope_2[0];l++)  
                {  
                    if(x1>=opera[i].ope_2[l])  
                        dr++;  
                }  
            else  
                for(int l=1;l<=opera[i].ope_2[0];l++)  
                {  
                    if(y1>=opera[i].ope_2[l])  
                        dc++;  
                }  
            }  
        else  
        {  
            if((x1==opera[i].ope_2[0]&&y1==opera[i].ope_2[1]))  
            {  
                x1=opera[i].ope_2[2];  
                y1=opera[i].ope_2[3];  
            }  
            else if(x1==opera[i].ope_2[2]&&y1==opera[i].ope_2[3])  
            {  
                x1=opera[i].ope_2[0];  
                y1=opera[i].ope_2[1];  
            }  
        }  
        x1+=dr;  
        y1+=dc;  
    }  
  
    return 1;  
}  
int main()  
{  
    //freopen("data.txt","r",stdin);  
    //freopen("printf.txt","w",stdout);  
    int r,c,n1,n2,x1,y1,x2,y2,kase=1;  
    while(scanf("%d%d%d",&r,&c,&n1)&&r)  
    {  
        memset(opera,0,sizeof(opera));  
        for(int i=0;i<n1;i++)  
        {  
            scanf("%s",opera[i].ope_1);  
            if(opera[i].ope_1[0]!='E')  
            {  
                scanf("%d",&opera[i].ope_2[0]);  
                for(int j=1;j<=opera[i].ope_2[0];j++)  
                scanf("%d",&opera[i].ope_2[j]);  
            }  
            else  
                for(int j=0;j<4;j++)  
                scanf("%d",&opera[i].ope_2[j]);  
        }  
        scanf("%d",&n2);  
        if(kase>1)  
            printf("\n");  
        printf("Spreadsheet #%d\n", kase++);  
        while(n2--)  
        {  
            scanf("%d%d",&x1,&y1);  
            //printf("@1:%d/n",x1);  
            int x2=x1,y2=y1;  
            if(!ope(x1,y1,n1))  
                printf("Cell data in (%d,%d) GONE\n", x2, y2);  
            else  
                printf("Cell data in (%d,%d) moved to (%d,%d)\n", x2, y2, x1, y1);  
  
        }  
    }  
    //printf("Time used=%2.3f\n",(double)clock()/CLOCKS_PER_SEC);  
}  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值