# Magic Trick（水题）

xiaoxiao2021-02-28  20

Description

Your friend has come up with a math trick that supposedly will blow your mind. Intrigued, youask your friend to explain the trick.

First, you generate a random positive integer k between 1 and 100. Then, your friend will giveyou n operations to execute. An operation consists of one of the four arithmetic operations ADD,SUBTRACT, MULTIPLY, or DIVIDE, along with an integer-valued operand x. You are supposed toperform the requested operations in order.

You don’t like dealing with fractions or negative numbers though, so if during the process, theoperations generate a fraction or a negative number, you will tell your friend that he messed up.

Now, you know the n operations your friend will give. How many of the first 100 positiveintegers will cause your friend to mess up?

Input

The first line of input contains a single positive integer n (1 ≤ n ≤ 10). Each of the next n linesconsists of an operation, followed by an operand. The operation is one of the strings ADD, SUBTRACT,MULTIPLY, or DIVIDE. Operands are positive integes not exceeding 5.

Output

Print, on a single line, a single integer indicating how many of the first 100 positive integers willresult in you telling your friend that he messed up.

Sample Input

1

SUBTRACT 5

Sample Output

4

Sample Input

1

DIVIDE 2

Sample Output

50

Sample Input

2

DIVIDE 5

Sample Output

80

#include <iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<stack> #include<queue> #include<deque> using namespace std; int main() { int t,b,count=0,c; char a; cin>>t; for(int i=1; i<=100; i++) c[i]=i; while(t--) { cin>>a>>b; if(a=='A') for(int i=1; i<=100; i++) if(c[i]!=-0x3f3f3f3f) c[i]+=b; if(a=='S') for(int i=1; i<=100; i++) if(c[i]!=-0x3f3f3f3f) c[i]-=b; if(a=='M') for(int i=1; i<=100; i++) if(c[i]!=-0x3f3f3f3f) c[i]*=b; if(a=='D') for(int i=1; i<=100; i++) if(c[i]!=-0x3f3f3f3f) { if(c[i]%b==0) c[i]/=b; else c[i]=-99999; } for(int i=1; i<=100; i++) if(c[i]<0&&c[i]!=-0x3f3f3f3f) { c[i]=-0x3f3f3f3f; count++; } } printf("%d\n",count); return 0; }