编程介的小学生 2017-08-29 10:33 采纳率: 20.5%
浏览 760
已采纳

Very Hard Problem

It was in the ancient world. ZOJ, the greatest treasure hunter in the world has been lost in the forest for more than 100 hours. Being with no food and no water for such a long time, he was really exhausted this night.

He then took out an old map, which was a very strange map. There are many stared positions on the map and it seems those stars are connected by some roads. "I'm sure the treasure is near me, but where is it?", said ZOJ, "If I can't find it, I will be laughed by others."

Suddenly, ZOJ noticed a slight light. "It was unsual.", said ZOJ and he started looking for the treasure again. After three hours' search, he finally found an entrance. But to enter the entrance, a puzzle should be solved.

The puzzle was described like this. Every time, you were given a character in the set {'-', '!', '~'} and a b-based number. You should take the character as an operator (i.e. '-' changes a number to its opposite number, '!' changes zero to one and non-zero value to zero, '~' takes bitwise operation NOT on all 64 bits of a number) and operates on the number. All you need to do is to print out the result.

The puzzle seemed quite simple, but ZOJ was only good at working out the output of the programs written by others, and had no idea about how to solve such a problem. So he turned to you for help.

Input

There are multiple test cases. In each test case, a character ch, a number b and a number n in b-based (2 ≤ b ≤ 16, when b is no less than 10, 'a'..'f' or 'A'..'F' are used) are given in order in one line. ch is assured to be in the set {'-', '!', '~'}, the number (n)b is assured in the range of a signed 64-bit integer. ch, b, n are seperated by one or more spaces. Leading or trailing spaces may also be added to the lines.

Output

For each test case, print one line, the 10-based result.

Sample Input

~ 10 4
! 10 0

  • 16 -F Sample Output

-5
1
15

  • 写回答

1条回答

  • threenewbee 2017-09-13 00:29
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能