Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:这种题有现成的库函数可用的……In Reply To:这种题有现成的库函数可用的…… Posted by:wpolly at 2007-06-15 06:16:25 > #include<stdio.h> > #include<stdlib.h> > #include<string.h> > char a[9], b[9], c[9], tmp[9]; > int main() > { > int n, x, y, z, m; > scanf("%d", &n); > while (n--) { > scanf("%s %s %s", a, b, c); > m = 1; > while (++m < 17) { > x = strtol(a, NULL, m); > y = strtol(b, NULL, m); > z = strtol(c, NULL, m); > if (x * y != z) > continue; > if (strcmp(a, itoa(x, tmp, m))) //关键步骤 > continue; > if (strcmp(b, itoa(y, tmp, m))) //关键步骤 > continue; > if (strcmp(c, itoa(z, tmp, m))) //关键步骤 > continue; > break; > } > printf("%d\n", m < 17 ? m : 0); > } > return 0; > } 因为比如用 strtol 转化的话 ,strtol("6", NULL, 3) 返回0, 这是不合题意的~ 我直接写 6 9 42 输出3 因为strtol 转化成3进制的话 分别是0 0 0; Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator