Official

A - Probably English Editorial by en_translator


For beginners
  • If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
  • Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
  • 競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.
  • C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.

In this problem, you need to check for each of the \(N\) words if it coincides with one of the five words.
One can write five if statements in a for statement, but there are a little simpler way: store the elements that are different in a if statement into an array and use a for statement instead.”
Specifically, construct the following array: word = {"and", "not", "that", "the", "you"}, then the for loop for \(i=0,1,2,3,4\) should contain an if statement like if(W_i == word[i]){result = true;}.
See also the sample code.

Sample code (C++):

#include<bits/stdc++.h>

using namespace std;

vector<string> word={"and", "not", "that", "the", "you"};

int main(){
  int n;
  cin >> n;
  bool res=false;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    for(auto &nx : word){
      if(s==nx){res=true;}
    }
  }
  if(res){cout << "Yes\n";}else{cout << "No\n";}
  return 0;
}

posted:
last update: