wikioi 1042 进制转换
来源:互联网 发布:单片机哪种好 编辑:程序博客网 时间:2024/03/29 05:15
http://wikioi.com/problem/1042/
负进制(什么*****)
int m=n; int k=0; int s; while(m!=0) { s=m/b; a[k]=m%b; if(m<0&&a[k]!=0)//这时a[k]会变为负数 { a[k]=a[k]-b;//转正 s++;//s应该加一 } m=s; k++; }
以-15 -2 为例
k s a[k] m
0 8 1 8
1 -4 0 -4
2 2 0 2
3 -1 0 -1
4 1 1 1
5 0 1 0
所以答案为110001
提供个样例
#include <cstdio>#include <algorithm>#include <cstring>#include <iostream>using namespace std;int n,b;int a[100]={0};int main(){ while(scanf("%d%d",&n,&b)==2) { memset(a,0,sizeof(a)); int m=n; int k=0; int s; while(m!=0) { s=m/b; a[k]=m%b; if(m<0&&a[k]!=0) { a[k]=a[k]-b; s++; } m=s; k++; } printf("%d=",n); for(int i=k-1;i>=0;i--) { if(a[i]>=10) { printf("%c",a[i]-10+'A'); } else printf("%d",a[i]); } printf("(base%d)\n",b); } return 0;}
- wikioi 1042 进制转换
- wikioi-1742
- wikioi-1038
- wikioi-1204
- wikioi-1205
- wikioi 高精度
- wikioi 2344
- wikioi 选课
- wikioi 1217
- Wikioi 3037
- wikioi 传话
- Wikioi 1000
- Wikioi 1001
- Wikioi 1002
- Wikioi 1004
- Wikioi 1007
- Wikioi 1009
- Wikioi 1010
- 写代码的女汉子
- Higher Math
- 12月3号面试题记录
- fecn-create和fecn-adapt的作用
- 基于visual Studio2013解决C语言竞赛题之0904文件排序
- wikioi 1042 进制转换
- TCP Keepalive 笔记
- SRM 599 DIV2 950
- Problem 56: 某种序列(大数加法+数列)
- Windows下Emacs+ Distel的配置
- pache 合理配置KeepAlive选项对服务器性能的影响
- openresty php luajit
- struts整合spring插件出现如下异常:Unable to load jar:struts2-spring-plugin-2.3.15.3.jar!/struts-plugin.xml
- 开发者的义不容辞