UVa355 - The Bases Are Loaded
来源:互联网 发布:学java编程语言 编辑:程序博客网 时间:2024/06/06 05:43
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
using namespace std;
int change1(char a)
{
if(a>='0' && a<='9')
return a-'0';
else
return a-'A'+10;
}
void solve(unsigned long long n, int k)
{
stack<int> ans;
int temp;
if(n==0) {
printf("0");
return;
}
while(n) {
ans.push(n%k);
n /= k;
}
while(!ans.empty()) {
temp = ans.top();
ans.pop();
if(temp<=9)
printf("%d",temp);
else
printf("%c",temp-10+'A');
}
}
int main()
{
int i, b1, b2, len, t;
char str[15];
bool flag;
unsigned long long sum, k;
while(cin>>b1>>b2) {
cin>>str;
len = strlen(str);
sum = 0;
k=1;
flag = true;
for(i=len-1; i>=0; i--) {
t = change1(str[i]);
if( (t >= b1 || t < 0) || str[i]=='-') {
cout << str << " is an illegal base " << b1 << " number" << endl;
flag = false;
break;
}
sum += t*k;
k *= b1;
}
if(flag) {
cout << str << " base " << b1 <<" = ";
solve(sum, b2);
cout << " base " << b2 << endl;
}
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
using namespace std;
int change1(char a)
{
if(a>='0' && a<='9')
return a-'0';
else
return a-'A'+10;
}
void solve(unsigned long long n, int k)
{
stack<int> ans;
int temp;
if(n==0) {
printf("0");
return;
}
while(n) {
ans.push(n%k);
n /= k;
}
while(!ans.empty()) {
temp = ans.top();
ans.pop();
if(temp<=9)
printf("%d",temp);
else
printf("%c",temp-10+'A');
}
}
int main()
{
int i, b1, b2, len, t;
char str[15];
bool flag;
unsigned long long sum, k;
while(cin>>b1>>b2) {
cin>>str;
len = strlen(str);
sum = 0;
k=1;
flag = true;
for(i=len-1; i>=0; i--) {
t = change1(str[i]);
if( (t >= b1 || t < 0) || str[i]=='-') {
cout << str << " is an illegal base " << b1 << " number" << endl;
flag = false;
break;
}
sum += t*k;
k *= b1;
}
if(flag) {
cout << str << " base " << b1 <<" = ";
solve(sum, b2);
cout << " base " << b2 << endl;
}
}
return 0;
}
- UVa355 - The Bases Are Loaded
- UVa 355 - The Bases Are Loaded
- UVA_355_The Bases Are Loaded
- coj 1433 Defend the Bases
- No symbol are loaded for any call stack frame.The source code cannot be displayed.
- The AssetBundle could not be loaded because it references scripts that are not compatible ...
- iptables: Firewall modules are not loaded
- iptables: Firewall modules are not loaded.
- iptables提示:Firewall modules are not loaded
- We Are The World
- We Are The Reason
- Are u the 10%?
- We are the champions
- hdu4283You Are the One
- we are the oiers
- You Are the One
- the way you are
- the session file could not be loaded
- Android入门第六篇之ListView (一)
- Hello World
- 在android 4.0 上面移植camera的一些心得 包括 单双camera 型号 hi253 gc0308 hi704 hm2055 ut2055 上层代码的调试
- 用Dialog创建带箭头的对话框
- 参加2012年职称英语考试
- UVa355 - The Bases Are Loaded
- Android入门第七篇之ListView (二)
- UVa389 - Basically Speaking
- CSS 选择器
- 成功软件项目管理的奥秘
- (PL之LUA)工欲善其事必先利其器——配置LUA
- UVa 374 Big Mod
- 梦想起点
- 大型网站运维探讨和心得