Answer to Question #155557 in C++ for Abu Ubayda

Question #155557

Anik’s family has a very strange eid tradition. On the day of eid, each member of the family has to offer some kind of gifts to each person they greet for the second time. The first time they meet they share only eid greetings and hug each other. Every time after that, they exchange gifts. Now, Anik has bought a lot of Toblerone chocolates as gifts. But after eating one himself, he finds that he doesn’t want to giveaway those chocolates. He knows who are visiting his room and in which order. He wants to know for each person in his list if he has to give a chocolate or not. He is not good at coding and not familiar with your coding expertise. Therefore, he came to you for help.

He has names of n people who will visit him in the given order. You need to tell, for each person, if Anik has to give gift or not.

Input Format

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

Constraints

n (1 ≤ n ≤ 100)

Output Format

Output n lines each containing either "YES" or "NO" (without quotes), depending on whether Anik need to give gift or not for the ith person in the list.

Sample Input 0

6
tom
lucius
ginny
harry
ginny
harry

Sample Output 0

NO
NO
NO
NO
YES
YES

Sample Input 1

3
a
a
a

Sample Output 1

NO
YES
YES
1
Expert's answer
2021-01-16T11:48:37-0500
#include <iostream>
#include <vector>
#include <string>
using namespace std;


bool find(vector<string>& names, string& temp){
    bool check = false;
    for(int i = 0; i < names.size(); i++)
    {
        if(names[i] == temp)
        {
            check = true;
        }
    }
    return check;
}


int main(){
    vector<string> names;
    int n;
    cin >> n;
    string temp;
    string answer = "";
    for(int i = 0; i < n; i++)
    {
        cin >> temp;
        if(find(names, temp))
        {
            answer += "YES\n";
            continue;
        }
        answer+="NO\n";
        names.push_back(temp);
    }
    cout << answer;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog