zoukankan      html  css  js  c++  java
  • UVa 512

    水题
    感觉操作数组删行添行比较麻烦
    可以把操作步骤存储下来, 每次搜索时逐步操作即可

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    
    using namespace std;
    
    const int maxn = 60;
    
    struct command{
        char c[5];  //操作名称
        int t;
        int mrk[100];
    };
    
    int main()
    {
        int a,b;
        int num = 0;
        struct command com[100];
        while( scanf("%d%d",&a,&b) && a )
        {
            if(++num != 1)  puts("");
            printf("Spreadsheet #%d
    ",num);
            int T;
            scanf("%d",&T);
            for( int i = 0; i < T; i++ )
            {
                scanf("%s",com[i].c);
                if( com[i].c[0] == 'E' ){
                    com[i].t = 4;
                    for( int j = 0; j < com[i].t; j++ )
                        scanf("%d",&com[i].mrk[j]);
                }
                else{
                    scanf("%d",&com[i].t);
                    for( int j = 0; j < com[i].t; j++ )
                        scanf("%d",&com[i].mrk[j]);
                }
            }
            int TT;
            scanf("%d",&TT);
            int x, y;
            while( TT-- )
            {
                scanf("%d%d",&x,&y);
                int x0 = x, y0 = y;
                for( int i = 0; i < T; i++ )
                {
                    int sum = 0;
                    if( com[i].c[0] == 'E' ){
                        if( ( x == com[i].mrk[0] && y == com[i].mrk[1] ) ){
                            x = com[i].mrk[2];
                            y = com[i].mrk[3];
                        }
                        else if( ( x == com[i].mrk[2] && y == com[i].mrk[3] ) ){
                            x = com[i].mrk[0];
                            y = com[i].mrk[1];
                        }
                    }
                    if( strcmp( com[i].c, "DR" ) == 0 ){
                        for( int j = 0; j < com[i].t; j++ ){
                            if( x > com[i].mrk[j] )     sum++;
                            else if( x == com[i].mrk[j] )   sum = x;
                        }
                        x -= sum;
                        if( x <= 0 )    break;
                    }
                    if( strcmp( com[i].c, "DC" ) == 0 ){
                        for( int j = 0; j < com[i].t; j++ ){
                            if( y > com[i].mrk[j] )     sum++;
                            else if( y == com[i].mrk[j] )   sum = y;
                        }
                        y -= sum;
                        if( y <= 0 )    break;
                    }
                    if( strcmp( com[i].c, "IR" ) == 0 ){
                        for( int j = 0; j < com[i].t; j++ )
                            if( x >= com[i].mrk[j] )     sum++;
                        x += sum;
                    }
                    if( strcmp( com[i].c, "IC" ) == 0 ){
                        for( int j = 0; j < com[i].t; j++ )
                            if( y >= com[i].mrk[j] )     sum++;
                        y += sum;
                    }
                }
                printf("Cell data in (%d,%d) ",x0,y0);
                if( x <= 0 || y <= 0 )  puts("GONE");
                else    printf("moved to (%d,%d)
    ",x,y);
            }
        }
        return 0;
    }
  • 相关阅读:
    udp tcp
    easy_install jinja2 mac linux
    linux 常用命令;
    Mac android 开发 sdk配置和手机连接
    ubuntu server 分区
    常见操作
    环境搭建相关
    ssh登录虚拟机上的linux
    算法学习
    转载一个 测试java类的玩意
  • 原文地址:https://www.cnblogs.com/JinxiSui/p/9740640.html
Copyright © 2011-2022 走看看