o.boj 1047 MODULO

注:最近这一系列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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值