洛谷P4325

博客详细介绍了洛谷P4325题目的内容,包括题意、输入输出格式和样例。题目要求计算10个不超过1000的非负整数对42取余后的不同余数个数。题解提供了简单的在线算法,即读取每个数,对其取余后放入集合中,最后输出集合大小作为答案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目

原题地址
题意翻译
描述

给出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
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.

题解

不需要离线,每读取一个数对其%42然后把结果放在一个set里就可以自动去重,结果打印set的大小即可。

代码

#include <iostream>
#include <set>
using namespace std;
int main(int argc, const char * argv[]) {
    int num;
    set<int> OUTPUT;
    for(int count = 0; count < 10; count++){
        cin >> num;
        OUTPUT.insert(num%42);
    }
    cout << OUTPUT.size() << endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值