SDUT 1252 进制转换
2016-07-17 21:52
381 查看
点击打开题目链接
#include <bits/stdc++.h> using namespace std; char _array[110];//数组模拟 int main() { int n, m; while(cin >> n >> m) { int k = 0, tmp = n; if(n == 0) { cout << '0' << endl; continue; } if(n < 0) { cout << '-'; n = -n; } while(n) { if(n%m > 9) { _array[k++] = n%m -10+ 'A'; } else { _array[k++] = n%m + '0'; } n /= m; } for(int i = k-1; i >= 0; i--) { printf("%c", _array[i]); } cout << endl; } return 0; } 2: #include <bits/stdc++.h> using namespace std; int main() { stack<char>S; char _char[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; int n, m; while(cin >> n >> m) { if(n < 0) { cout << '-'; n = -n; } if(n == 0) { cout << '0' << endl; continue; } while(n) { S.push(_char[n%m]); n /= m; } while(!S.empty()) { printf("%c", S.top()); S.pop(); } cout << endl; } return 0; }
相关文章推荐
- C++基于栈实现铁轨问题
- 浅析C语言中堆和栈的区别
- C语言栈的表示与实现实例详解
- C语言实现颠倒栈的方法
- 算法系列15天速成 第十天 栈
- 一看就懂:图解C#中的值类型、引用类型、栈、堆、ref、out
- Array栈方法和队列方法的特点说明
- java数据结构之java实现栈
- 浅析栈区和堆区内存分配的区别
- 用Java代码实现栈数据结构的基本方法归纳
- 用PHP解决的一个栈的面试题
- 浅谈C#中堆和栈的区别(附上图解)
- C#使用Object类实现栈的方法详解
- JavaScript数据结构与算法之栈详解
- C语言之栈和堆(Stack && Heap)的优缺点及其使用区别
- Python实现栈的方法
- JavaScript数组的栈方法与队列方法详解
- JavaScript数据结构与算法之栈与队列
- JavaScipt中栈的实现方法
- Java中堆和栈的区别详解