https://www.nowcoder.com/pat/2/problem/267
吐槽:水题
#include<cstdio>
#include<cstring>
char str[50];
int change(int sum,int x){
memset(str,0,sizeof(str));
int k = 0,ans = 0;
do{
int tmp = sum % x;
if(tmp > 9) str[k++] = tmp + 'A' - 10;
else str[k++] = tmp + '0';
sum /= x;
}while(sum!=0);
for(int i = 0;i <= k;i++){
if(str[i] == '1')
ans++;
}
return ans;
}
int main(){
int n,r;
while(scanf("%d%d",&n,&r) != EOF){
printf("%d\n",change(n,r));
}
return 0;
}