博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Gym 100733G No Negations
阅读量:4677 次
发布时间:2019-06-09

本文共 2589 字,大约阅读时间需要 8 分钟。

题目:

  

It is late at night and you found a logical expression on the blackboard, which you believe is the secret to figure out if your gang is going to be attacked tomorrow.

Your immediate reaction is to copy the expression and take it to the big bosses. Luckily, you remembered that mafia bosses don't enjoy surprises, and they want your expression to be simple and clean.

Given the logical expression in the board, having variables represented by english letters A-Z, and the operators OR and AND, simplify it using Morgan's law, that is:

To help you, we will use the following format:

  • [A + B] = (a * b) or
  • [A + b] = (a * B) or
  • [a + B] = (A * b) or
  • [A * B] = (a + b) or
  • [A * b] = (a + B) or
  • [a + B] = (A + b)

This is also valid for three or more variables. The expression will have variables, represented by letters A-Z: if it is a lower case letter, it is a negated variable. It may also have parenthesis that group expressions, so you must solve the expressions between the parenthesis first. There may also be square brackets, in which case you must apply the rules above.

Don't simplify the expression beyond applying the rules described in the problem.

Input

The input is a logical expression having at most 200 characters. Each character can be a variable (A-Z), a negated variable (a-z), the operator OR (+) or the operator AND (*). Also, it can have parenthesis. A negation is represented by a lowercase character or a logic block between square brackets ([ ]).

Output

Print the simplified logic expression.

Sample Input

Input
[J+b+V*a]
Output
(j*B*v+A)
Input
i+i+G+m*((f))
Output
i+i+G+m*((f))
Input
v+a*(M*[T*b*N*U*g*G+x+O])
Output
v+a*(M*(t+B+n+u+G+g*X*o))
Input
g*[Q+w+[l*(j)]]
Output
g*(q*W*(l*(j))) 题意:   大概就是给你个字符串,当你发现[]使,将里面的大写字母变成小写,小写字母变为大写,*号变加号,+号变乘号,否则原样输出 分析:    弄个栈按题意来就可以。
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 char s[201]; 9 stack
k;10 int main()11 {12 scanf("%s",s);13 int n=strlen(s);14 int num=0;15 for(int i=0;i
='A'&&s[i]<='Z')36 s[i]=tolower(s[i]);37 else if(s[i]>='a'&&s[i]<='z')38 s[i]=toupper(s[i]);39 else if(s[i]=='*')40 s[i]='+';41 else if(s[i]=='+')42 s[i]='*';43 }44 }45 else46 {47 if(s[i]=='[')48 {49 num++;50 s[i]='(';51 k.push(s[i]);52 }53 }54 }55 printf("%s\n",s);56 return 0;57 }
View Code

 

转载于:https://www.cnblogs.com/forwin/p/4807015.html

你可能感兴趣的文章
《麻辣江湖》即将上线!
查看>>
Mybatis中mapper.xml文件判断语句中的单双引号问题
查看>>
frameset和frame
查看>>
饥饿的小易(规律,同余大数)
查看>>
ats透明代理
查看>>
PHP 小代码
查看>>
2016/03/16 codes
查看>>
2018年7月21日工作总结
查看>>
Linux shell 命令判断执行语法 ; , && , ||
查看>>
vim代码格式化插件clang-format
查看>>
What does the dot after dollar sign mean in jQuery when declaring variables?
查看>>
windows registry
查看>>
jquery 动画总结(主要指效果函数)
查看>>
【BZOJ4155】[Ipsc2015]Humble Captains
查看>>
【事件】阻止事件的冒泡
查看>>
mac os 安装 geckodriver
查看>>
【数据分析 R语言实战】学习笔记 第十一章 对应分析
查看>>
谁的青春不迷茫
查看>>
socket知识总结
查看>>
Qt做的简易图片浏览
查看>>