MBUT 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 += b. The machine code is 80 AF BF.

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

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

    4.ADD B, A means b += a. The 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

题意:给出指令,模拟蒸汽机器人-布里茨CPU里面的两个寄存器的相加或者自增

分析:模拟

这题由于是读入的16进制的数字,所以输入可以写成scanf("%x",&a);那么输

#pragma comprint(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<stdlib.h>
#include<time.h>
#include<algorithm>
#define LL __int64
#define FIN freopen("in.txt","r",stdin)
char str[1000000];
int main()
{
    int t;
    int a,b;
    scanf("%d",&t);
    while(t--)
    {
        memset(str,0,sizeof(str));
        scanf("%x %x",&a,&b);
        getchar();
        gets(str);
        int i=0;
        int len=strlen(str);
        while(i<len)
        {
            if(str[i]=='8' && str[i+1]=='0')
            {
                if(str[i+3]=='A' && str[i+4]=='F' && str[i+6]=='B' && str[i+7]=='F') a+=b;
                else if(str[i+3]=='B' && str[i+4]=='F' && str[i+6]=='A' && str[i+7]=='F') b+=a;
                i+=9;
            }
            if(str[i]=='F' && str[i+1]=='0')
            {
                if(str[i+3]=='A' && str[i+4]=='F') a+=a;
                else if(str[i+3]=='B' && str[i+4]=='F') b+=b;
                i+=6;
            }
            if(str[i]==' ') i++;
        }
        printf("%X %X\n",a,b);
    }
    return 0;
}
View Code

 

入就直接把读入的16进制数用10进制保存下来了。

这题的话,数据可能会有负数,所以输出的话,用printf("%X %X",a,b);这是输出大写的16进制数,如果要输出小写的16进制数,大写的X改成小写的x就好。

 

posted @ 2015-08-21 23:01  Cliff Chen  阅读(201)  评论(0编辑  收藏  举报