POJ 3191 The Moronic Cowmpouter
来源:互联网 发布:linux如何退出root权限 编辑:程序博客网 时间:2024/06/06 00:09
题目大意:
由于对数字艺术不敏感,cows只能尝试建造一台计算引擎帮他完成一些计算工作(而不能凭自己的直觉来解决问题了)。他打算设计一个十进制向二进制转换的程序,但不过不是二进制而是负二进制的,并且他们发现用负二进制表示数字时可以不需要符号位!他们开心极了。
同样,-2进制各位权值计算方法和普通进制一样,最低位为1,依次往上为-2( (-2)^1 ),4( (-2)^2 ),-8( (-2)^3 )......,因此10进制的1, 2, 3, 4在-2进制中就表示为1, 110, 111, 100,怪异的是10进制负数用-2进制表示同样也只包含0和1而不带符号位,例如-1, -2, -3, -4在-2进制中表示为11, 10, 1101, 1100, 1111
现只有一个测例,测例中给出一个整数n(-2,000,000,000 ≤ n ≤ 2,000,000,000),将其转换成-2进制数并输出。
题目链接
注释代码:
/* * Problem ID : POJ 3191 The Moronic Cowmpouter * Author : Lirx.t.Una * Language : C * Run Time : 0 ms * Run Memory : 176 KB */ #include <stdio.h>//正基数#defineBASE2//reverse base//反基数#defineVBASE-2#defineMAXSTKSIZE1000intstk[MAXSTKSIZE];//栈intmain() {intn;//输入的十进制数inttop;//栈顶inti;//计数变量scanf("%d", &n);if ( !n ) {puts("0");return 0;}top = 0;while ( n ) {stk[++top] = n % BASE;if ( n < 0 )//如果n为负数,“余数”需取反//因为-2进制不带符号位,因此每一位必然是//1或者0而不可能会是一个负数stk[top] = -stk[top];n -= stk[top];//将余数减去n /= VBASE;//进制右移一位}while ( top )printf("%d", stk[top--]);putchar('\n');return 0;}
无注释代码:
#include <stdio.h>#defineBASE2#defineVBASE-2#defineMAXSTKSIZE1000intstk[MAXSTKSIZE];intmain() {intn;inttop;inti;scanf("%d", &n);if ( !n ) {puts("0");return 0;}top = 0;while ( n ) {stk[++top] = n % BASE;if ( n < 0 )stk[top] = -stk[top];n -= stk[top];n /= VBASE;}while ( top )printf("%d", stk[top--]);putchar('\n');return 0;}
单词解释:
moronic:adj, 低能的,迟钝的
inexperienced:adj, 缺乏经验的
pleased:adj, 高兴的,欢喜的
sign:n, 符号
sign bit:n, 符号位
power:n, 指数,幂
eerily:adj/adv, 怪诞,奇异
counterpart:n, 副本,配对物
express:vt, 表达,表示; n, 快递
explanation:n, 说明,解释
bronze:n, 青铜; adj, 青铜色的
0 0
- POJ 3191 The Moronic Cowmpouter
- poj 3191 The Moronic Cowmpouter
- POJ 3191 The Moronic Cowmpouter
- POJ 3191The Moronic Cowmpouter
- [POJ 3191 The Moronic Cowmpouter]数学
- POJ 3191 The Moronic Cowmpouter 可能会
- POJ 3191 The Moronic Cowmpouter 笔记
- PKU 3191 The Moronic Cowmpouter
- pku 3191 The Moronic Cowmpouter
- POJ 3191 The Moronic Cowmpouter 负二进制转换
- poj 3191 The Moronic Cowmpouter 十进制转-2进制
- poj 3191The Moronic Cowmpouter (负进位制)
- Poj 3191 The Moronic Cowmpouter【十进制转负二进制】
- POJ 3191 The Moronic Cowmpouter (-2进制转换)
- Poj 3191 The Moronic Cowmpouter【十进制转负二进制】
- POJ3191-The Moronic Cowmpouter
- POJ3191- The Moronic Cowmpouter 十进制转负n进制
- The Moronic Cowmpouter poj3191(负进制转换以及其他进制转换模板)
- cocos2d-x内存管理
- PHP中的闭包详解
- SVM安装找不到文件包
- Page cache和buffer cache的区别与联系
- QUIC简介
- POJ 3191 The Moronic Cowmpouter
- Android TraceView工具使用
- 加密解密helper
- 第四周-项目四-数组做数据成员
- 第四周 三角形类
- SSH原理与运用:远程登录
- zoj 3211 Dream City 贪心+动规
- ligerUI分页bug
- javascript学习手记(Html)meta标签之详解