UVA 575

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=516

本题在于进制之间的转换,十进制换其他进制就除k取余法,反之则加余乘k

View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 void zhuanhua(char *s,int *a)//把字符转化为数组存入数组
 5 {
 6  int i=0;
 7  while(*s)
 8      {
 9       a[i]=(*s)-48;
10       i++;
11       s++;
12      }
13 }
14 int main()
15 {
16  int i,j,len,a[100],sum;
17  char str[100];
18  while(scanf("%s",str))
19      {
20       sum=0;
21       if(strlen(str)==1&&str[0]=='0')
22           break;//当只输入0时退出
23       len=strlen(str);
24       zhuanhua(str,a);
25       for(i=0;i<len;i++)
26           sum+=a[i]*(pow(2,len-i)-1);//模拟加k乘余的方法
27       printf("%d\n",sum);
28      }
29      return 0;
30 }

 

转载于:https://www.cnblogs.com/huzhenbo113/articles/2915817.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值