Tom Riddle’s Diary (CodeForces - 855A)

描述了一道编程题目,涉及字符串比较,需要检查给定的n个人物是否拥有过日记,输出“YES”或“NO”。
摘要由CSDN通过智能技术生成

第一周题单

G - Tom Riddle’s Diary (CodeForces - 855A)

Harry Potter is on a mission to destroy You-Know-Who’s Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle’s diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name s i s_i si in the i i i-th line, output “YES” (without quotes) if there exists an index j j j such that s i   =   s j s_i = s_j si=sj and j   <   i j < i j<i, otherwise, output “NO” (without quotes).

Input

First line of input contains an integer n ( 1   ≤   n   ≤   100 ) n (1 ≤ n ≤ 100) n(1 n 100) — the number of names in the list.
Next n n n lines each contain a string s i s_i si, consisting of lowercase English letters. The length of each string is between 1 and 100.

Output

Output n n n lines each containing either “YES” or “NO” (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).

Simple1

Input

6
tom
lucius
ginny
harry
ginny
harry

Output

NO
NO
NO
NO
YES
YES

Simple2

Input

3
a
a
a

Output

NO
YES
YES

Note

In test case 1, for i   =   5 i = 5 i= 5 there exists j   =   3 j = 3 j= 3 such that s i   =   s j s_i = s_j si=sj and j   <   i j < i j<i, which means that answer for i   =   5 i = 5 i= 5 is “YES”.

题目大意

给定 n n n行字符串,如果本行的字符串在前面出现则输出"YES",否则输出"NO"

题解过程

用一个字符串数组承接输入数据,每输入一行字符串就往回找看是否有相同的字符串

代码部分(cpp)
#include <iostream>
#include <cstring>
using namespace std;
void solution()
{
    int n;
    cin >> n;
    string a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (i != 0)
        {
            bool check = 0;
            for (int j = i - 1; j >= 0; j--)
            {
                if (a[i] == a[j])
                {
                    cout << "YES" << endl;
                    check = 1;
                    break;
                }
            }
            if (!check)
            {
                cout << "NO" << endl;
            }
        }
        else
        {
            cout << "NO" << endl;
        }
    }
}
int main(int argc, const char **argv)
{
    solution();
    return 0;
}

刚开始学习,欢迎指正

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值