shunfurh 于 2017.08.29 18:33 提问

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个回答

caozhy      2017.09.13 08:29

POJ 3104 Drying（二分搜索，最大化最小值）
Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11464   Accepted: 2967 Description It is very hard to wash and especially to dry clothes in winter.
POJ3104 Drying (二分的力量2)
﻿﻿ Description It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She is not afraid of this boring process. Jane has decided to use a radiator to m
uva 10523 Very Easy !!!
Very Easy !!! Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description THE SAMS' CONTEST Problem 4  V
Codeforces 706C Hard problem(dp+字符串)
C. Hard problem time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy is fond of solving different tasks.
nyoj103 A+B ProblemII
A+B Problem II 时间限制：3000 ms  |  内存限制：65535 KB 难度：3 描述 I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. A,B must be positi
cs231n Lecture 2

POJ - 3104 Drying(二分最大化最小值)

hdu1018（求n！的位数）
Problem Description In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you ar
Machine Schedule（最小点覆盖=最大匹配）
Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12012   Accepted: 5118 Description As we all know, machine scheduling is a very classical
[ACMcoder] A + B Problem II
Problem Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. Input The first line of the input contains an integer T(1 Output F