您的位置:首页 > 其它

o.boj 1047 MODULO

2011-12-17 10:05 274 查看
注:最近这一系列ACM的内容,都是2年多之前的代码,自己回顾一下。

MODULO

Submit: 1398 Accepted:830
Time Limit: 1000MS Memory Limit: 65556K
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: