标签:ring namespace -- for ret == char s %s scanf
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
void convert(int in[], int len, int out[],int &ks, int m, int n) {
for (int i = 0; i < len;) {
int k = 0;
for (int j = i; j < len; ++j) {
int temp = k * m + in[j];
in[j] = temp / n;
k = temp % n;
}
out[ks++] = k;
while (in[i] == 0) i++;
}
}
int main() {
char s[1000];
while (scanf("%s", s) != EOF) {
int n = strlen(s);
int in[1000];
for (int i = 0; i < n; ++i) {
in[i] = s[i] - '0';
}
int mid[1000];
int ks=0;
convert(in, n, mid,ks, 10, 2);
int out[1000];
int ks2=0;
convert(mid,ks,out,ks2,2,10);
for (int j = ks2-1; j >=0 ; --j) {
printf("%d",out[j]);
}
printf("\n");
}
return 0;
}
标签:ring namespace -- for ret == char s %s scanf
原文地址:https://www.cnblogs.com/ailinal/p/12387368.html