UVa 389 Basically Speaking
生活随笔
收集整理的這篇文章主要介紹了
UVa 389 Basically Speaking
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
又一道基礎(chǔ)題,進(jìn)制轉(zhuǎn)換。
做水題也不能大意!
1 //68ms 2010-05-14 15:48:58
2 ?//log: wa(1) ac(1)
3 //Type: Base number conversion(進(jìn)制轉(zhuǎn)換)
4 //key1: strrev() 在ANSI C, C++ 中不能使用
5 //key2: 0的時(shí)候要處理
6 //Thinking: After finished coding, member to try some special data.
7 #include <stdio.h>
8 #include <string.h>
9 #define NL 100
10
11 int get(char a)
12 {
13 if (a >= '0' && a <= '9') return a-'0';
14 return a-'A'+10;
15 }
16
17 int main()
18 {
19 char s0[NL], s1[NL];
20 int len, I, K, M, b1, b2;
21 while (scanf("%s%d%d", s0, &b1, &b2) != EOF) {
22 len = strlen(s0);
23 int t = 0, bb = 1;
24 I = len - 1;
25 while (I>=0) {
26 t += get(s0[I])*bb;
27 bb *= b1;
28 I--;
29 }
30 K = 0;
31 while (t>0) {
32 I = t%b2;
33 if (I>=10) s1[K++] = I-10+'A';
34 else s1[K++] = I+'0';
35 t /= b2;
36 }
37 if (K == 0) { s1[K++] = '0'; }
38 s1[K] = '\0';
39 if (K > 7) puts(" ERROR");
40 else {
41 for (I=0, M=K-1; M>=0; M--) {
42 s0[I++] = s1[M];
43 }
44 s0[I] = '\0';
45 printf("%7s\n", s0);
46 }
47 }
48 return 0;
49 }
50 /*
51 input:
52 0000000 2 2
53 */
?
轉(zhuǎn)載于:https://www.cnblogs.com/superbin/archive/2010/05/14/1735546.html
總結(jié)
以上是生活随笔為你收集整理的UVa 389 Basically Speaking的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大型门户网站架构设计的可伸缩性
- 下一篇: ShopEx安装过程