整除的尾数
Time limit 1000 ms
Memory limit 32768 kB
问题描述
一个整数,只知道前几位,不知道末二位,被另一个整数除尽了,那么该数的末二位该是什么呢?
输入
输入数据有若干组,每组数据包含二个整数a,b(0<a<10000, 10<b<100),若遇到0 0则处理结束。
输出
对应每组数据,将满足条件的所有尾数在一行内输出,格式见样本输出。同组数据的输出,其每个尾数之间空一格,行末没有空格。
输入样例
200 40
1992 95
0 0
输出样例
00 40 80
15
原题链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2099
分析
将输入的 n 转为字符处理,更方便在末尾添加位数,在转化为整数对 m 求模,记录符合要求的尾数
注:
该代码尚未通过原题链接的考察
解题代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char array[10] = { '\0' }, result[100][3] = { '\0' };
int a, b, temp, length, count;
int i, j;
count = 0;
while(scanf("%d %d", &a, &b) != EOF)
{
if(a == 0 && b == 0)
{
break;
}
if(a > 0 && a < 10000 && b > 10 && b < 100)
{
sprintf(array, "%d", a);
length = strlen(array);
for(i = 0; i < 10; i++)
{
for(j = 0; j < 10; j++)
{
array[length] = i + '0';
array[length + 1] = j + '0';
temp = atoi(array);
if(temp % b == 0)
{
result[count][0] = i + '0';
result[count][1] = j + '0';
count++;
}
}
}
for(i = 0; i < count - 1; i++)
{
printf("%s ", result[i]);
}
printf("%s\n", result[i]);
for(i = 0; i < 10; i++)
{
array[i] = '\0';
}
count = 0;
}
else
{
break;
}
}
}