In the distant space, there is a technologically advanced planet.
在那遥远的太空,有一个科技发达的星球(B612)
One day they provided the Earth with a code that could achieve the ultimate meaning of the universe. People were very happy, but found that this code can only run on computers with a word length of 47 bits. As a good computer scientist, you need to implement a tool to simulate running this code on our computer.
一天,他们给地球送去了一份代码,这份代码可以穷尽宇宙的终极意义。人们老高兴了,但是发现这份代码只能在47位电脑上运行,作为一个优秀的计算机科学家,你得去模拟个工具来促使这份代码在我们的计算机上运行。
This tool needs to simulate the following instructions:
这个工具需要激励(激励-响应即输入-输出)以下命令
"def x n" : define a unsigned 47 bits integer variable named x, with initial value n, n is an integer in [0, 2^47-1]
def x n :定义一个47位无符号整数变量,变量名为x,初始值为n,n是个47位正整数【范围如上】。
"add x y" : means x = x + y
意味着x被赋予了x+y的和
"sub x y" : means x = x - y
。。以下以此类推
"mul x y" : means x = x * y
"div x y" : means x = x / y, we guarantee y is not zero
"mod x y" : means x = x % y, we guarantee y is not zero
When the result of addition and multiplication cannot be represented by 47 bits, the part above 47 bits is truncated.
当加法和乘法的结果(和与乘积)不能以47位表示时,超过47位的部分应当被截除。
When the result of subtraction is less than zero, the result should add 2^47.
当减法的结果小于0时,结果应当加上2的47次幂。
The name of each variable only contains letters and the length does not greater than 20.
每个变量的名字只由字母组成且长度不超过20.
Input
Contains multiple lines of input, one instruction per line.
包含多行输入,一行一条指令
Output
For each instruction, output the value of the first argument after calculation. For example, "def abc 100", then your output will be "abc = 100" in a line with no quotation marks.
对于每条指令,输出计算后的第一个变量值及其名字。
See Sample Output for more information.
Sample Input
def six 6
def abc 1
def bcd 0
sub bcd abc
add abc six
def universe 0
mul abc six
add universe abc
div bcd six
mod bcd abc
Sample Output
six = 6
abc = 1
bcd = 0
bcd = 140737488355327
abc = 7
universe = 0
abc = 42
universe = 42
bcd = 23456248059221
bcd = 5
变量名?变量值?我们很容易就能想到万能的KEY-VALUE红黑树:STL-MAP<>
这道题的思路很简单,而且意外地,题目的数据并不是很大,暴力模拟完全行得通。
题目中涉及到的map的基本指令会在代码中给出。
#include
#include
//#include
#include
以下是暴力代码
#include
#include
//#include
#include
#include
#include
#include
#include
#define DETERMINATION main
#define lldin(a) scanf("%lld",&a)
#define din(a) scanf("%d",&a)
#define printlnlld(a) printf("%lld\n",a)
#define printlnd(a) printf("%d\n",a)
#define printlld(a) printf("%lld",a)
#define printd(a) printf("%d",a)
#define reset(a,b) memset(a,b,sizeof(a))
const int INF=0x3f3f3f3f;
using namespace std;
const double PI=acos(-1);
typedef long long ll;
typedef long double ld;
///Schlacht von Stalingrad
/**Although there will be many obstructs ahead,
the desire for victory still fills you with determination..**/
string command;
struct va
{
string name;
ll value;
} variables[900000];
ll cnt=0;
int DETERMINATION()
{
ll ulim=1<<30;
ulim*=(1<<17);
ulim--;
// cout<>command)
{
if(command[0]=='d'&&command[1]=='e')
{
cin>>variables[cnt].name;
cin>>variables[cnt].value;
cout<>a>>b;
ll tmp=0,loc=0,loc2=0;
for(int i=0; ilim)
variables[loc].value%=lim;
while(variables[loc].value<0)
variables[loc].value+=lim;
cout<