poj 1546
来源:互联网 发布:淘宝运营推广公司 编辑:程序博客网 时间:2024/06/06 00:15
进制转换问题,很重要,尤其是搜索中用于状态的表示。这题把目标进制弄成十进制再用栈来转换成目标进制就好了。
以下是代码:
- #include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
char dic[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
char digit[10];
int chang;
int stack[100],top;
int n,m; - void change1()
{
int len=strlen(digit);
chang=0;
for(int i=0;i<len;i++)
if(digit[i]!=' ' && digit[i]!='0')
{
int temp;
if(digit[i]>='1' && digit[i]<='9') temp=digit[i]-'0';
else if(digit[i]=='A') temp=10;
else if(digit[i]=='B') temp=11;
else if(digit[i]=='C') temp=12;
else if(digit[i]=='D') temp=13;
else if(digit[i]=='E') temp=14;
else if(digit[i]=='F') temp=15;
chang+=pow(n,len-i-1)*temp;
}
} - void change2()
{
top=0;
int i;
while(chang)
{
int temp=chang%m;
stack[top++]=temp;
chang/=m;
}
} - int main()
{
// freopen("in.txt","r",stdin);
while(scanf("%s",digit)==1)
{
scanf("%d%d",&n,&m);
change1();
change2();
if(top>7)
printf(" ERROR");
else
{
int i;
for(i=0;i<7-top;i++)
printf(" ");
while(top)
{
printf("%c",dic[stack[top-1]]);
top--;
}
}
printf("/n");
}
return 0;
}
- poj 1546
- poj 1546
- POJ 1546 Basically Speaking
- POJ 1546 Basically Speaking
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- 页面只显示前一部分,后一部分不见了
- yum 安装 gcc ,g++
- C++的背影 ——C++之父Bjarne Stroustrup印象(作者:左轻侯)
- [解题报告]Balloons in a Box
- org.apache.catalina.loader. WebappClassLoader.ENABLE_CLEAR_REFERENCES
- poj 1546
- 算法题9 查找链表中倒数第k个结点
- 一些软件设计的原则
- 算法题10 求1+2+...+n
- 算法题11 判断整数序列是不是二元查找树的后序遍历结果
- linux下安装配置svn独立服务器
- Android StatusBar 更改
- [解题报告]Ural 1011 Conductors
- 百度“框”应用 开发者抱怨不赚钱