Untitled conversation
- User
[APC001] B - Checker
题目背景
小 K 正在出公开赛。他有一个 idea,但他担心重题,因此,他需要确认这题是不是重题。不过他还有很多事情要做,因此他把这个任务交给了你。
题目描述
题库里共有 道题目,每道题目的名称都是一个长度不足 的字符串。设题目名称长度为 ,我们定义两道题为重题当且仅当两道题题目名称有 的相同位置的字符相同。
- Assistant
小 K 正在出公开赛。他有一个 idea,但他担心重题,因此,他需要确认这题是不是重题。不过他还有很多事情要做,因此他把这个任务交给了你。
题库里共有 道题目,每道题目的名称都是一个长度不足 的字符串。设题目名称长度为 ,我们定义两道题为重题当且仅当两道题题目名称有 的相同位置的字符相同。
现在小 K 把这道题交给了你,希望你帮他查重(即,将自己的题目与其他的题目进行一一比对,判断是否为重题)。
先输入一个正整数 表示题库中的题目数量,之后输入一个字符串 表示小 K 出的题目的名称。
之后 行每行一个字符串表示这些题目的名称。
输入的每个字符串长度相同。
两行,第一行输出重题数量,若没有重题则第二行输出 Good job!,否则输出 Make persistent efforts.。
3
chachong
abcabcat
chocolat
noiprp++
0
Good job!
10
apc001_b
apc001_b
apc001_b
apc001_b
apc001_b
apc001_b
apc001_b
apc001_b
apc001_b
apc001_b
apc001_b
10
Make persistent efforts.
25
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
0
Good job!
【样例解释 #1】
题目名为 chachong,与第一题中的 个字符相同,与第二题中的 个字符相同,与第三题中的 个字符相同,而每题都有 个字符,没有与小 K 出的题目有大于等于 个字符相同的题目。
【样例解释 #2】
请注意有可能在题库中也包含重题。
【数据规模】
对于 的数据,保证 ,每个字符串长度相同,且不含不可见字符。
请使用 C++ 作答
To solve the problem, we need to determine how many existing problem names in the database are considered duplicates ("重题") of the new problem name based on the specified criteria. Two problem names are duplicates if they share at least half of their characters in the same positions, rounded up.
Approach:
Input Reading:
n and the new problem name s.k of the problem name s and calculate the threshold for duplication, which is ceil(k / 2).n existing problem names and compare them with s.Comparison Logic:
s.Output:
C++ Implementation:
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int k = s.length();
int threshold = (k + 1) / 2; // ceil(k / 2)
int duplicate_count = 0;
for(int i = 0; i < n; ++i){
string t;
cin >> t;
int matches = 0;
for(int j = 0; j < k; ++j){
if(s[j] == t[j]) matches++;
}
if(matches >= threshold){
duplicate_count++;
}
}
cout << duplicate_count << "\n";
if(duplicate_count == 0){
cout << "Good job!";
}
else{
cout << "Make persistent efforts.";
}
}
Explanation of the Code:
Input Handling:
n and the new problem name s.threshold) using the ceiling function.Processing Each Existing Problem:
t and counts how many characters match with s at the same positions.Output:
This implementation efficiently processes up to 10,000 problem names with lengths up to 9 characters, ensuring that it meets the problem's constraints.