uva 343 What Base Is This?
2010-05-14 14:37
330 查看
无意中看到了《Art of programming contest》 UVa的,感觉不错,还发现的一个大牛的博客,里面有UVA及ragional and world final 的很多解题报告
本想上去水一道题,谁知却被水了。
本想上去水一道题,谁知却被水了。
//20ms 2010-05-14 14:30:43 //wa(6) ce(1) ac(1) //Type:基础算法进制转换 //key1:没有一进制 //key2:使用unsigned long long #include <stdio.h> #include <string.h> #define NL 100 inline int get(char a) { if (a >= '0' && a<='9') return a-'0'; else return a-'A'+10; } unsigned long long did(char *s, int b, int L) { int i, j; unsigned long long t = 0, b0 = 1; i = L-1; j = 0; while (i >= 0) { int k = get(s[i]); t += k*b0; b0 *= b; i--; } return t; } int main() { char s1[NL], s2[NL]; int len1, len2, d1, d2; int i; while (scanf("%s%s", s1, s2) != EOF) { len1 = strlen(s1); len2 = strlen(s2); d1 = 1; i = 0; int k; while (i<len1) { k = get(s1[i]); if (k > d1) d1 = k; i++; } d1++; d2 = 1; i = 0; while (i<len2) { k = get(s2[i]); if (k > d2) d2 = k; i++; } d2++; int b1, b2; bool suc = false; for (b1 = d1; b1<=36; b1++) { for (b2 = d2; b2<=36; b2++) { unsigned long long L1 = did(s1, b1, len1); unsigned long long L2 = did(s2, b2, len2); if (L1 == L2) { suc = true; break; } } if (suc) break; } if (suc) { printf("%s (base %d) = %s (base %d)\n", s1, b1, s2, b2); }else { printf("%s is not equal to %s in any base 2..36\n", s1, s2); } } return 0; }
相关文章推荐
- UVA343 UVALive5451 What Base Is This?【进制】
- UVa343 What Base Is This
- UVa 343 - What Base Is This?
- uva 343 What Base Is This?
- The BASEDIR environment variable is not defined correctly This environment variable is needed to run
- uva 10209 Is This Integration ? (计算几何)
- What Is the Purpose of This Book?
- UVA - 10056 What is the Probability ?
- uva 10056 - What is the Probability ?(概率)
- what is this api
- Uva 10107 - What is the Median?
- SpringMVC整合Swagger出现Unable to infer base url. This is common when using dynamic servlet 错误
- Here is what can get this system to converge
- 一份好的简历应该是这样的(This Is What A GOOD Resume Should Look Like)
- JS:what is this "Object.prototype" anyway...?
- uva 10056 What is the Probability ? 概率是多少
- uva 10056 - What is the Probability ?
- what is this?
- android.util.AndroidRuntimeException Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? com.uethinking.microvideo.manag
- uva 10107 - What is the Median?