NBUT 1450 Blitzcrank

  • [1450] Blitzcrank

  • 时间限制: 1000 ms 内存限制: 65535 K
  • 问题描述
  • Blitzcrank  is a robot.

    There are some pretty good registers(寄存器) in Blitzcrank's body.

    There are some instructions about register A and register B:

    1.ADD A, B means a += bThe machine code is 80 AF BF.

    2.ADD A, A means a += aThe machine code is F0 AF.

    3.ADD B, B means b += bThe machine code is F0 BF.

    4.ADD B, A means b += aThe machine code is 80 BF AF.

    Now give you the values in register A and register B and some machine codes. You should calculate out the final value in register A and register B after operating the machine code.

  • 输入
  • The frist line contains an integer T, means there are T test cases.
    For each test case, the first line contains two integers means the initial value of the register A and the register B in hexadecimal(十六进制).
    The next line contains a series of hexadecimal numbers.
  • 输出
  • For each test case, print the register A and register B's value in hexadecimal.
  • 样例输入
  • 2
    A1 B2
    80 AF BF F0 AF
    B2 B3
    F0 AF F0 BF
  • 样例输出
  • 2A6 B2
    164 166
    
  • 提示
  • The first case's machine codes 80 AF BF F0 AF is composed of ADD A, B and ADD A, A.
  • 来源
  • Monkeyde17

    这题目其实挺水的,我写着题的目的主要是想分享一下刚学到的超神string和stringstream的用法。

    这题目是说给出两个十六进制的数A和B,通过输入特定字符串进行操作,同样用十六进制输出操作后的A和B。
    具体操作为:

    1.当输入“80 AF BF”时,a += b;

    2.当输入“F0 AF”时,a += a.

    3.当输入“F0 BF”时b += b

    4.当输入“80 BF AF”时,b += a. 


    这题主要就是考察字符串的处理。用普通的方法可以很快敲出来:
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    const int mx=1e6+10;
    char s[mx];
    int a,b,l;
    
    int main() {
        int t;
        scanf("%d",&t);
        while(t--) {
            scanf("%X %X",&a,&b);
            getchar();
            gets(s);        //由于操作次数不确定,所以用scanf难以控制,则用gets比较方便
            l=strlen(s);
            int i=0;
            while(i<l)
            {
                if(s[i]=='8')
                {
                    if(s[i+3]=='A' )
                        a+=b;
                    else if(s[i+3]=='B')
                        b+=a;
                    i+=9;
                }
                else if(s[i]=='F')
                {
                    if(s[i+3]=='A')
                        a+=a;
                    else if(s[i+3]=='B')
                        b+=b;
                    i+=6;
                }
            }
            printf("%X %X\n",a,b);      //此处的%x和%X要区分开,用大写输出的字母就是大写,用小写就输出小写字母
        }
        return 0;
    }
    

    不过这个代码不是我要展示的重点,我觉得特别神奇的是string

    /*
    Author:ZXPxx
    Memory: 268 KB		Time: 343 MS
    Language: G++		Result: Accepted
    */
    
    #include<cstring>
    #include<iostream>
    #include<sstream>
    #include<cstdio>
    using namespace std;
    stringstream sbuf;
    int main() {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int A,B;
            string str,op,a,b;
            cin>>hex>>A>>B;
            sbuf.clear();
            cin.ignore();
            getline(cin,str);
            sbuf<<str;
            while(sbuf>>op)
            {
                if(op=="80")
                {
                    sbuf>>a>>b;
                    if(a=="AF")
                        A+=B;
                    else
                        B+=A;
                }
                else
                {
                    sbuf>>a;
                    if(a=="AF")
                        A+=A;
                    else
                        B+=B;
                }
            }
            printf("%X %X\n",A,B);
        }
        return 0;
    }
    

    就像处理整形数据一样,好方便啊……
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值