Known Notation

题目地址:Known Notation

解题思路:

o(︶︿︶)o 唉。

代码:

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <sstream>
 4 #include <cstdlib>
 5 #include <cstring>
 6 #include <cstdio>
 7 #include <string>
 8 #include <bitset>
 9 #include <vector>
10 #include <queue>
11 #include <stack>
12 #include <cmath>
13 #include <list>
14 //#include <map>
15 #include <set>
16 using namespace std;
17 /***************************************/
18 #define ll long long
19 #define int64 __int64
20 #define PI 3.1415927
21 /***************************************/
22 const int INF = 0x7f7f7f7f;
23 const double eps = 1e-8;
24 const double PIE=acos(-1.0);
25 const int d1x[]= {0,-1,0,1};
26 const int d1y[]= {-1,0,1,0};
27 const int d2x[]= {0,-1,0,1};
28 const int d2y[]= {1,0,-1,0};
29 const int fx[]= {-1,-1,-1,0,0,1,1,1};
30 const int fy[]= {-1,0,1,-1,1,-1,0,1};
31 const int dirx[]= {-1,1,-2,2,-2,2,-1,1};
32 const int diry[]= {-2,-2,-1,-1,1,1,2,2};
33 /*vector <int>map[N];map[a].push_back(b);int len=map[v].size();*/
34 /***************************************/
35
36 int main()
37 {
38     int cas;
39     scanf("%d",&cas);
40     while(cas--)
41     {
42         char s[1005];
43         scanf("%s",s);
44         int i,j;
45         int len=strlen(s);
46         int numN=0,numX=0;
47         int sum=0;
48         for(i=0;i<len;i++)
49         {
50             if (s[i]<=‘9‘&&s[i]>=‘0‘)
51                 numN++;
52             if (s[i]==‘*‘)
53                 numX++;
54         }
55         sum=numX+1-numN;
56         if (sum<0)
57             sum=0;
58         int numn=sum,ce=0;
59         for(i=0;i<len;i++)
60         {
61             if (s[i]<=‘9‘&&s[i]>=‘0‘)
62                 numn++;
63             if (s[i]==‘*‘)
64             {
65                 if (numn>=2)
66                 {
67                     numn-=1;
68                 }
69                 else
70                 {
71                     ce++;
72                     numn+=1;
73                     sum++;
74                 }
75             }
76         }
77         if (!ce&&s[len-1]!=‘*‘&&numX)
78             sum++;
79         printf("%d\n",sum);
80     }
81     return 0;
82 }

时间: 2024-08-06 16:25:37

Known Notation的相关文章

ACM学习历程——ZOJ 3829 Known Notation (2014牡丹江区域赛K题)(策略,栈)

Description Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science. It is also known as postfix notation since every operator in an expression follows all of its operands. Bob is a student in

leetcode-Evaluate the value of an arithmetic expression in Reverse Polish Notation

leetcode 逆波兰式求解 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are+,-,*,/. Each operand may be an integer or another expression. Some examples: ["2", "1", "+", "3", "

[LeetCode]Evaluate Reverse Polish Notation

题目:Evaluate Reverse Polish Notation 给出一个加减乘除的逆波兰式,求出它的结果: 什么是逆波兰式? 简单来说,逆波兰式就是表达式的后缀表示形式: 例如下面两个式子: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13", "5", &quo

LeetCode150 Evaluate Reverse Polish Notation

Evaluate the value of an arithmetic expression in Reverse Polish Notation.  (Medium) Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: ["2", "1", "+", "3", "*&

Evaluate Reverse Polish Notation

Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Example ["2", "1", "+", "3", "*"] -> ((2

lintcode 中等题:Evaluate Reverse Polish notation逆波兰表达式求值

题目 逆波兰表达式求值 在逆波兰表达法中,其有效的运算符号包括 +, -, *, / .每个运算对象可以是整数,也可以是另一个逆波兰计数表达. 样例 ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13", "5", "/", "+"]

zoj 3826 Hierarchical Notation(模拟)

题目链接:zoj 3826 Hierarchical Notation 题目大意:给定一些结构体.结构体有value值和key值,Q次询问,输出每一个key值相应的value值. 解题思路:思路非常easy.写个类词法的递归函数,每次将key值映射成一个hash值,用map映射每一个key的value起始终止位置,预处理完了查询就非常easy了. 这题是最后10分钟出的.由于没有考虑value为{}的情况,导致RE了.可是zoj上显示的是SE,表示不理解什么意思,事实上就是RE.只是另一个地方会

Evaluate Reverse Polish Notation——LeetCode

Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: ["2", "1", "+", "3", "*"] -&g

ZOJ 3829 Known Notation (2014牡丹江H题)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5383 Known Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science. I

zoj3826 Hierarchical Notation (字符串模拟)

Hierarchical Notation Time Limit: 2 Seconds      Memory Limit: 131072 KB In Marjar University, students in College of Computer Science will learn EON (Edward Object Notation), which is a hierarchical data format that uses human-readable text to trans