#P12856. 预处理器
预处理器
预处理器
Problem Description
yummy 正在写一个 C++ 程序,程序的开头有 行宏定义,具体地,对于 ,第 行只可能是下面四种之一,其中 均为数字:
#define Si x
,用N x
来表示,保证 。#define Si Sa<<Sb
,用< a b
来表示。#define Si Sa+Sb
,用+ a b
来表示。#define Si Sa*Sb
,用* a b
来表示。 本题中,我们假定程序中的int
类型可以存储任意大的数字而不发生溢出,并且a<<b
完全等价于 。 对于每个 ,计算cout<<(Si)<<endl;
的输出对 取余的结果。 保证程序可以在有限时间内编译成功。
Input
输入的第一行有一个正整数 (),表示宏定义的行数。 之后 行,每行有一个宏定义语句,格式见题目描述。
Output
输出 行,每行一个自然数,其中第 行输出 cout<<(Si)<<endl;
的结果对 取余的结果。
Sample Input
5
N 3
N 1
< 1 2
+ 5 5
* 3 3
Sample Output
3
1
6
6144
48
Hint
因为数值比较小,所以不会发生溢出。选手不难使用如下程序验证:
#define S1 3
#define S2 1
#define S3 S1<<S2
#define S4 S5+S5
#define S5 S3*S3
#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<(S1)<<endl;
cout<<(S2)<<endl;
cout<<(S3)<<endl;
cout<<(S4)<<endl;
cout<<(S5)<<endl;
return 0;
}
Source
2025“钉耙编程”中国大学生算法设计暑期联赛(9)