杭电acm1229
http://acm.hdu.edu.cn/showproblem.php?pid=1229
这题,是我想多了
ac代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> int main() // 代码一AC { const int right[8] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000}; int a, b, k; while (scanf("%d%d%d", &a, &b, &k) != EOF && (a != 0 || b != 0)) { if (a % right[k] == b % right[k]) printf("%d\n", -1); else printf("%d\n", a + b); } return 0; }
wa代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> int kk(int a,int b,int k) { int sa[10],sb[10]; int i,j,s; i=j=0; while(a) { sa[i++]=a%10; a/=10; } while(b) { sb[j++]=b%10; b/=10; } s=0; while(s<i&&s<j&&(k--)) { if(sa[s]!=sb[s]) return 0; s++; } return 1; } int main() { int a,b,k; while(scanf("%d%d%d",&a,&b,&k)&&(a||b)) { if(kk(a,b,k)) { printf("-1\n"); continue; } printf("%d\n",a+b); } return 0; }