題目鏈接
題目描述
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.
題意翻譯
描述
給出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取余
輸入輸出樣例
輸入 #1
1
2
3
4
5
6
7
8
9
10
輸出 #1
10
輸入 #2
42
84
252
420
840
126
42
84
420
126
輸出 #2
1
輸入 #3
39
40
41
42
43
44
82
83
84
85
輸出 #3
6
說明/提示
In the first example, the numbers modulo 42 are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10. In the second example all numbers modulo 42 are 0. In the third example, the numbers modulo 42 are 39, 40, 41, 0, 1, 2, 40, 41, 0 and 1. There are 6 distinct numbers.
代碼:
#include<iostream>
using namespace std;
int num[42], count[42] = {0}, flag = 0;
int main()
{
for(int i = 0; i < 10; i++)
{
cin >> num[i];
count[num[i] % 42]++;
}
for(int i = 0; i < 42; i++) if(count[i] > 0) flag++;
cout << flag << endl;
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/261382.html
標籤:其他
