编程介的小学生 2017-05-25 02:28 采纳率: 20.5%
浏览 726
已采纳

Geek Challenge [SKRZAT] (Base Minus Two)

Problem Description
Problem F: Geek Challenge SKRZAT
Geek Challenge [SKRZAT] is an old, old game from Poland that uses a game console with two buttons plus a joy stick. As is true to its name, the game communicates in binary, so that one button represents a zero and the other a one. Even more true to its name, the game chooses to communicate so that the base of the number system is minus two, not plus two, so we’ll call this representation “Weird Binary”. Thus the bit positions label the powers of minus two, as seen in the following five-bit tables:

Numbers are presented on the screen in Weird Binary, and then numbers are accepted in response from the console as a stream of zeroes and ones, terminated by a five-second pause.
You are writing a computer program to support the novice geek in playing the game by translating numbers between decimal and Weird Binary.

Input
The first line in the file gives the number of problems being posed without any white space. Following are that many lines. Each line will either be a conversion into Weird Binary or out of Weird Binary: the letter "b" indicates that the rest of the line is written in Weird Binary and needs to be converted to decimal; the letter "d" indicates that the rest of the line is written in decimal and needs to be converted to Weird Binary.
The input data are in the range to fit within a 15-bit Weird Binary number, which represents the decimal number range –10922 to 21845, inclusive.

Output
For each conversion problem, show the type of problem, its input string, and the converted result in the format shown below, replicating even the spacing exactly as shown. Leading zeroes are not allowed.

Sample Input
10
b 1001101
b 0111111
b 101001000100001
b 010010001000010
b 100110100110100
d -137
d 137
d 8191
d -10000
d 21000

Sample Output
From binary: 1001101 is 61
From binary: 0111111 is -21
From binary: 101001000100001 is 19937
From binary: 010010001000010 is -7106
From binary: 100110100110100 is 15604
From decimal: -137 is 10001011
From decimal: 137 is 110011001
From decimal: 8191 is 110000000000011
From decimal: -10000 is 10100100110000
From decimal: 21000 is 101011000011000

  • 写回答

1条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭