注:最近这一系列ACM的内容,都是2年多之前的代码,自己回顾一下。
Description
Given two integers A and B, A modulo B is the remainder when dividing A by B. For example, the numbers 7, 14, 27 and 38 become 1, 2, 0 and 2, modulo 3. Write a program that accepts 10 numbers as input and outputs the number of distinct numbers in the input, if the numbers are considered modulo 42.
Input
The input will contain 10 non-negative integers, each smaller than 1000, one per line.
Output
Output the number of distinct values when considered modulo 42 on a single line.
Sample Input
39
40
41
42
43
44
82
83
84
85
Sample Output
6
Hint
In the example, the numbers modulo 42 are 39, 40, 41, 0, 1, 2, 40, 41, 0 and 1. There are 6 distinct numbers.
Source
Croatian Open Competition in Informatics
求一组数据模42所得的各不相等的余数的个数。水题,直接申请一个42位辅助数组记录相应余数是否出现过,没出现过的count+1即可
#include <stdio.h>
main()
{
int num[43] = {0};
int temp, i, j, count = 0;
for (i = 0; i < 10; i++)
{
scanf("%d", &temp);
temp %= 42;
if (!num[temp])
{
num[temp]++;
count ++;
}
}
printf("%d\n", count);
// system("pause");
return 0;
}