http://acm.hdu.edu.cn/showproblem.php?pid=1229
水题,我的代码:
#include<stdio.h>
bool judge(int a,int b,int k)
{
int i,c=1;
for(i=0;i<k;i++)
c*=10;
if(a%c==b%c)
return true;
return false;
}
int main()
{
int a,b,k;
while(scanf("%d%d%d",&a,&b,&k)!=EOF)
{
if(a==0 && b==0) break;
if(judge(a,b,k))
printf("-1/n");
else
printf("%d/n",a+b);
}
return 0;
}
本文提供了一道来自HDU OJ编号为1229的题目解决方案。该题主要考察整数的位运算及简单数学判断。通过C语言实现了一个名为judge的函数来检查两个整数在特定位数上的尾数是否相等。

被折叠的 条评论
为什么被折叠?



