博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1010 Radix
阅读量:7037 次
发布时间:2019-06-28

本文共 1538 字,大约阅读时间需要 5 分钟。

题目链接:

进制转换,但是没有拿到满分,还有点小问题,下面是代码

1 #include
2 #include
3 using namespace std; 4 5 long trans(string num,int radix){ 6 int in[10] = {
1}; 7 for(int i = 1; i < 10; i++){ 8 in[i] = in[i-1]*radix; 9 }10 int x = num.size();11 long stem = 0;12 for(int i = x-1; i >= 0; i--){13 if(num[i] >= '0' && num[i] <= '9'){14 stem += (int)(num[i]-'0')*in[x-i-1];15 }16 else{17 stem += ((int)(num[i]-'a')+10)*in[x-i-1];18 }19 }20 return stem;21 }22 int main(){23 string str[2];24 int n,radix;25 std::ios::sync_with_stdio(false);26 std::cin.tie(0);27 int n_1 = 0;28 while(cin >> str[0]){29 cin >> str[1]>>n>>radix;30 long stem = 0, stem_x = 0;31 int max = 0,ste,radix_x = 0;32 stem = trans(str[n-1],radix);33 n_1 = str[2-n].size();34 for(int i = 0; i < n_1; i++){35 if(str[2-n][i] >= '0' && str[2-n][i] <= '9'){36 ste = (int)(str[2-n][i]-'0');37 }38 else{39 ste = (int)(str[2-n][i]-'a')+10;40 }41 if(ste > max) max = ste;42 }43 radix_x = max+1;44 while(stem_x < stem){45 stem_x = trans(str[2-n],radix_x);46 radix_x++;47 }48 if(stem_x == stem) cout << radix_x-1 << endl;49 else cout << "Impossible" << endl;50 }51 return 0;52 }

 

转载于:https://www.cnblogs.com/huhusw/p/9755091.html

你可能感兴趣的文章
我的友情链接
查看>>
fix [Errno 13] Permission denied: '/var/log/glance/api.log'
查看>>
Cacti 0.8.8b 插件(monitor thold setting realtime)安装及邮件 短信告警
查看>>
我的友情链接
查看>>
很好的一个文字工具网址
查看>>
前辈文章摘要
查看>>
CentOS 5.5安装配置Trac1.0
查看>>
我的友情链接
查看>>
超强整理:2012年网页设计趋势
查看>>
sqoop2 五分钟实例
查看>>
线性筛素数
查看>>
通过Windows 8 Powershell轻松创建USB引导盘
查看>>
基础总结篇之二:Activity的四种launchMode
查看>>
理解python中可变对象作为默认参数
查看>>
C++ 操作Office的Access数据库
查看>>
iOS开发——keychain的使用
查看>>
avahi-daemon服务
查看>>
论坛外链如何才能快速收录?
查看>>
热备份路由协议,vlan与生成树(STP)之间的关系
查看>>
CentOS操作MySQL问题集锦
查看>>