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:WA,无奈中In Reply To:WA,无奈中 Posted by:Pro_zq at 2009-08-27 15:12:55 > #include <stdio.h> > #include <string.h> > > int main() > { > char n1[20 + 1], n2[20 + 1]; > > int s; > > int i, j; > > scanf("%s%s", n1, n2); > > s = 0; > for(i = 0; i < strlen(n1); ++i) > { > for(j = 0; j < strlen(n2); ++j) > { > s += (n1[i]-'0') * (n2[j]-'0'); > } > } > > printf("%d\n", s); > > return 0; > } > >这个错哪儿了= =|| >希望牛人指点下 改成这样就好了 因为你之前的 for(i = 0; i < strlen(n1); ++i) { n1[i] -= '0'; } for(i = 0; i < strlen(n2); ++i) { n2[i] -= '0'; } 假如n1[i] = 1200, strlen(n1) = 4,因为n1 = {49, 50, 48, 48, 0, ?, ?...} 你先将所有数字减'0',会变成n1 = {1, 2, 0, 0, 0, ?, ?, ...} 因此strlen(n1) = 2 下面的两个for回圈就错掉了。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator