• [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

    这题目事实上挺水的,我写着题的目的主要是想分享一下刚学到的超神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;
    }

    就像处理整形数据一样,好方便啊……

NBUT 1450 Blitzcrank的更多相关文章

  1. NBUT 1457 莫队算法 离散化

    Sona Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Submit Status Practice NBUT 145 ...

  2. ACM: NBUT 1107 盒子游戏 - 简单博弈

     NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  3. ACM: NBUT 1105 多连块拼图 - 水题 - 模拟

    NBUT 1105  多连块拼图 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  4. ACM: NBUT 1646 Internet of Lights and Switches - 二进制+map+vector

    NBUT 1646 Internet of Lights and Switches Time Limit:5000MS     Memory Limit:65535KB     64bit IO Fo ...

  5. NBUT 1525 Cow Xor(01字典树+前缀思想)

    [1525] Cow Xor 时间限制: 2000 ms 内存限制: 65535 K 问题描述 农民约翰在喂奶牛的时候被另一个问题卡住了.他的所有N(1 <= N <= 100,000)个 ...

  6. NBUT 1186 Get the Width(DFS求树的宽度,水题)

    [1186] Get the Width 时间限制: 1000 ms 内存限制: 65535 K 问题描述 It's an easy problem. I will give you a binary ...

  7. NBUT 1635 Explosion(最小顶点覆盖)

    [1635] Explosion 时间限制: 10000 ms 内存限制: 65535 K 问题描述 there is a country which contains n cities connec ...

  8. NBUT 1602 Mod Three(线段树单点更新区间查询)

    [1602] Mod Three 时间限制: 5000 ms 内存限制: 65535 K 问题描述 Please help me to solve this problem, if so, Liang ...

  9. NBUT 1028 该减肥了(简单递推)

    [1028] 该减肥了 时间限制: 1000 ms 内存限制: 65535 K 问题描述 由于长期缺乏运动,Teacher Xuan发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥.Teach ...

随机推荐

  1. iOS 蓝牙的GameKit用法

    一.连接蓝牙 显示可以连接的蓝牙设备列表 - (IBAction)buildConnect:(id)sender { // 创建弹窗 GKPeerPickerController *ppc = [[G ...

  2. PostgreSQL执行机制的初步学习

    作为开源数据库的新手,近日有兴对比了Pg和MySQL的查询计划. 通过Pg源码目录下的src\backend\executor\README文件,加上一些简单调试,就能对Pg的执行机制产生一个初步印象 ...

  3. 「Python调试器」,快速定位各种疑难杂症!!

    现在很多的编辑器其实都带着「调试程序」的功能,比如写 c/c++ 的 codeblocks,写 Python 的 pycharm,这种图形界面的使用和显示都相当友好,简单方便易学,这个不是我这篇文章要 ...

  4. CAD参数绘制多行文字(网页版)

    在CAD设计时,需要绘制多行文字,用户可以设置设置绘制文字的高度等属性. 主要用到函数说明: _DMxDrawX::DrawMText 绘制一个多行文字.详细说明如下: 参数 说明 DOUBLE dP ...

  5. [JOYOI] 1051 选课

    题目限制 时间限制 内存限制 评测方式 题目来源 1000ms 131072KiB 标准比较器 Local 题目描述 学校实行学分制.每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分.学校 ...

  6. 树莓派 -- bcm2835 library (1)

    bcm2835 library提供了user space 操作IO的代码. 本文不涉及代码分析,先直观的按照user guide完成操作. 1. 在Raspberry中安装bcm2835 librar ...

  7. 灰度直方图均衡化----python实现

    直方图均衡化是使用图像直方图进行对比度调整的图像处理的方法. 该方法通常会增加许多图像的整体对比度,尤其是当图像的可用数据由接近的对比度值表示时. 通过这种调整,强度可以更好地分布在直方图上. 这允许 ...

  8. (十三)python 3 集合

    定义: 1.不同元素组成 2.无序 3.集合中的元素必须是不可变类型 创建集合 s = {1,2,3,4,5,6,7,8} 1.定义可变集合 >>> set_test = set(' ...

  9. 建仓类型与对应建仓价MT4

    建仓类型与对应建仓价 (Bid,Ask) 建仓类型 对应建仓价 Buy Ask+Spread Sell Bid-Spread BuyLimit Ask-Spread-StopLevel SellLim ...

  10. 集训第六周 E题

    E - 期望(经典问题) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit S ...