58 lines
1.1 KiB
C
58 lines
1.1 KiB
C
#include <stdio.h>
|
|
|
|
void DigiTran(int k, char res[]);
|
|
|
|
int s;
|
|
|
|
int main() {
|
|
while (scanf("%d", &s)) {
|
|
if (s == -1) {
|
|
return 0;
|
|
}
|
|
char res[233];
|
|
DigiTran(s, res);
|
|
printf("%s ", res);
|
|
}
|
|
}
|
|
|
|
int ws(int a) {
|
|
int ans = 0;
|
|
while (a) {
|
|
ans++;
|
|
a /= 10;
|
|
}
|
|
return ans;
|
|
}
|
|
|
|
void DigiTran(int k, char res[]) {
|
|
int rr[233];
|
|
if (k == 0) {
|
|
res[0] = 'A';
|
|
res[1] = '\0';
|
|
return;
|
|
}
|
|
int n = ws(k);
|
|
for (int i = 0; i < n; i++) {
|
|
rr[n - i - 1] = k % 10;
|
|
k /= 10;
|
|
}
|
|
// rr 为将数组拆解为一位一位的数组
|
|
int ki = 0; // 标识 res 位数
|
|
for (int i = 0; i < n; i++) {
|
|
if (i == n - 1) {
|
|
res[ki++] = rr[i] + 'A';
|
|
continue;
|
|
}
|
|
int ls = rr[i] * 10 + rr[i + 1];
|
|
// 如果两位数字符合条件
|
|
if (ls >= 10 && ls <= 25) {
|
|
res[ki++] = ls + 'A';
|
|
i++;
|
|
// 替换两位需要将 i++
|
|
} else {
|
|
//如果不符合,只用一位变换
|
|
res[ki++] = rr[i] + 'A';
|
|
}
|
|
}
|
|
res[ki] = '\0';
|
|
} |