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
+= 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的更多相关文章
- NBUT 1457 莫队算法 离散化
Sona Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Submit Status Practice NBUT 145 ...
- ACM: NBUT 1107 盒子游戏 - 简单博弈
NBUT 1107 盒子游戏 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- ACM: NBUT 1105 多连块拼图 - 水题 - 模拟
NBUT 1105 多连块拼图 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- 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 ...
- NBUT 1525 Cow Xor(01字典树+前缀思想)
[1525] Cow Xor 时间限制: 2000 ms 内存限制: 65535 K 问题描述 农民约翰在喂奶牛的时候被另一个问题卡住了.他的所有N(1 <= N <= 100,000)个 ...
- 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 ...
- NBUT 1635 Explosion(最小顶点覆盖)
[1635] Explosion 时间限制: 10000 ms 内存限制: 65535 K 问题描述 there is a country which contains n cities connec ...
- NBUT 1602 Mod Three(线段树单点更新区间查询)
[1602] Mod Three 时间限制: 5000 ms 内存限制: 65535 K 问题描述 Please help me to solve this problem, if so, Liang ...
- NBUT 1028 该减肥了(简单递推)
[1028] 该减肥了 时间限制: 1000 ms 内存限制: 65535 K 问题描述 由于长期缺乏运动,Teacher Xuan发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥.Teach ...
随机推荐
- 分析HTTP 2.0与HTTP 1.1区别
1.什么是HTTP 2.0 HTTP/2(超文本传输协议第2版,最初命名为HTTP 2.0),是HTTP协议的的第二个主要版本,使用于万维网.HTTP/2是HTTP协议自1999年HTTP 1.1发布 ...
- swift potocol 作为参量时函数的派发顺序
1.检查protocol本体是否声明调用函数: 2.如果没有,检查protocol扩展是否有该函数:如果扩展中也没有,报错: 3.如果本体声明了函数,使用动态派发机制进行派发:扩展中的实现位于最末位.
- 【原创】webbluetoorh 在windows下无法显示搜索列表,在mac下正常的解决办法
google webbluetooth在windows下不能弹出设备搜索列表提示“Web Bluetooth API is not available”,因为webbluetooth是google新推 ...
- Java SE、Java EE、Java ME 三者区别
现在一个个来分析 1. Java SE(Java Platform,Standard Edition).Java SE 以前称为 J2SE.它允许开发和部署在桌面.服务器.嵌入式环境和实时环境中使用的 ...
- anchor_target_layer中的bounding regression
在anchor_target层,这两行是计算bounding regression代码: bbox_targets = np.zeros((len(inds_inside), 4), dtype=np ...
- BZOJ4318: OSU! (概率DP)
题意:一个串 给出每个字符为1的可能性 否则为0 一段连续的1能获得长度的立方的收益 问总收益的期望 题解:设x_i为到第i位时连续的1的期望长度 由i-1递推来的贡献 如果这一位是0没有贡献 如果是 ...
- 第3节 mapreduce高级:7、自定义outputformat实现输出到不同的文件夹下面
2.1 需求 现在有一些订单的评论数据,需求,将订单的好评与差评进行区分开来,将最终的数据分开到不同的文件夹下面去,数据内容参见资料文件夹,其中数据第九个字段表示好评,中评,差评.0:好评,1:中评, ...
- linux中查看文件指定行的数据
http://jingyan.baidu.com/article/15622f24125872fdfdbea560.html
- “完美”解决微信小程序购物车抛物动画,在连续点击时出现计算错误问题,定时器停不下来。
最近做,微信点餐小程序,遇到添加商品时出现抛物动画,参考借鉴了这位大神的方法 https://www.cnblogs.com/greengage/p/7815842.html 但出现了一个问题,连续点 ...
- [GXOI/GZOI2019]宝牌一大堆(dp)
luogu bzoj 这个麻将题还算挺友善的,比隔壁zjoi的要好得多... 比较正常的做法是五维dp 但事实上六维dp也是完全不会被卡的 七对子选权值最高的七个,国士无双直接$13^2$暴力 ...