uva-343 进制转换
2012-08-13 23:26
162 查看
#include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX_L 128 int find_min(char *s) { char cc='0'; while(*s) { if(*s>cc) cc=*s++; else s++; } if(cc=='0') return 2; else if(cc<='9') return cc-'0'+1; else return cc-'A'+11; } int conv(char *s, int base) { int len=strlen(s), w=1, sum=0; while(len-->0) { if(s[len]>='A') sum+=w*(s[len]-'A'+10); else sum+=w*(s[len]-'0'); w*=base; } return sum; } int main(void) { char n1[MAX_L], n2[MAX_L]; int i, j, m1, m2, b1, b2, flag=0; #ifndef ONLINE_JUDGE freopen("p.in", "r", stdin); #endif while(scanf("%s%s", n1, n2)!=EOF) { flag=0; m1=find_min(n1); m2=find_min(n2); for(i=m1; i<=36 && !flag; i++) for(j=m2; j<=36 && !flag; j++) if(conv(n1, b1=i) == conv(n2, b2=j)) flag=1; if(!flag) printf("%s is not equal to %s in any base 2..36\n", n1, n2); else printf("%s (base %d) = %s (base %d)\n", n1, b1, n2, b2); } return 0; }
相关文章推荐
- UVa343 What Base Is This
- uva 128 Software CRC(进制转换)
- uva 343 What Base Is This?
- UVA10473 Simple Base Conversion【进制转换】
- UVa 11121 Base -2 / 进制转换
- uva 188 Perfect Hash(进制转换 + 遍历)
- UVA 11121 Base -2 (进制转换)
- UVa 343 - What Base Is This?
- UVa 10473 Simple Base Conversion (两句话实现进制转换)
- uva 343 What Base Is This?
- UVa290 - Palindroms <---> smordnilaP(进制转换、回文)
- UVA343 UVALive5451 What Base Is This?【进制】
- uva 128 - Software CRC(进制转换)
- UVa 128 Software CRC / 进制转换
- UVa 11461 - Square Numbers
- UVA 10125 Sumsets 技巧性的枚举
- UVA11735_Corner the Queens
- UVA 673(括号匹配)
- UVa - 12450 - SpaceRecon Tournament
- UVa 1601 - The Morning after Halloween(单向BFS版)