题意翻译
描述
给出10个整数,问这些整数%42后有多少个不同的余数。 输入
输入包含10个小于1000的非负整数,每行一个。 输出
输出它们%42后,有多少个不同的余数。 说明
第一个样例的十个结果是1,2,3,4,5,6,7,8,9,10,有10个不同的结果;第二个样例结果都是0,只有一个不同的结果;第三个样例余数是39,40,41,0,1,2,40,41,0,1,有0,1,2,39,40,41这六个不同的结果。
感谢@ACdreamer 提供的翻译
注明:%42为除以42取余
题目描述
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.
输入输出格式
输入格式:The input will contain 10 non-negative integers, each smaller than 1000, one per line.
输出格式:Output the number of distinct values when considered modulo 42 on a single line.
输入输出样例
输入样例#1:
1
2
4
3
5
8
6
7
9
10
输出样例#1: 10
输入样例#2: 复制
42
84
252
420
126
840
42
126
84
420
输出样例#2: 复制
1
输入样例#3: 复制
39
40
42
41
43
83
44
82
84
85
输出样例#3: 复制
6
#include <stdio.h>
#include <stdlib.h>
#define N 10
int temp[1000];//此处定义42个“桶”就行啦
int num[11];
int i,j,ans=0,c;
int main()
{
for(i=0;i<N;i++)
scanf("%d",&num[i]);//输入部分
for(j=0;j<N;j++)
{
c=num[j]%42;
temp[c]++; //桶里面加一
}
for(i=0;i<42;i++)
{
if(temp[i]!=0) //有些桶为1,有些桶>1,没出现过的为0
ans++;
}
printf("%d",ans);
return 0;
}
简单的桶排序应用,出现的数字,只要相同下标的桶(数组),里面+1,这样可以直接输出不为0的桶下标即实现排序。
本题,则是通过桶记出现过的数。