Problem:
B : Books / 本
Problem
大学生のいづあ君はかなりの読書家である。面白そうだと思った本は迷わず買うため、蔵書が増えすぎて管理できなくなっているのが悩みである。そこでいづあ君は、持っている本の中から目的の本を検索するシステムを作ることにした。
全ての本は次の 3 つの属性を持つ。
title
: 本のタイトルを表す文字列である。
author
: 本の著者を表す文字列である。
date
: 本の出版日を表す
2014/07/07
のような形式をした文字列である。
検索のクエリは次のような形式で与えられる。
Q_title
Q_author
Q_date_from
Q_date_to
Q_title
: タイトルに文字列
Q_title
を含む本がヒットする。
Q_author
: 著者名に文字列
Q_author
を含む本がヒットする。
Q_date_from
: 出版日が
Q_date_from
と同じかそれより後である本がヒットする。
Q_date_to
: 出版日が
Q_date_to
と同じかそれより前である本がヒットする。
ただし、クエリに
*
(アスタリスク)が指定された場合は任意の文字列にヒットする。ある本がヒットするかの判定は上記 4 つの論理積で行われる。つまり、 1 つ以上ヒットしていない属性がある場合はその本はヒットしていないものとする。(「ヒットする」とは本が検索クエリに合致することを意味する。)
いづあ君の仕事は与えられたクエリを順に処理するプログラムを書くことである。
Input
入力は次の形式で与えられる。
N
book 1
...
book N
Q
query 1
...
query Q
N
はいづあ君が持っている本の数であり、続く
N
行にはそれぞれの本に関する情報が続く。本に関する情報は次のような形式である。
title
author
date
Q
は検索クエリの数であり、続く
Q
行にクエリが続く。検索のクエリは次のような形式で与えられる。
Q_title
Q_author
Q_date_from
Q_date_to
Constraints
N
,
Q
は整数である。
1 ≦
N
≦ 100
1 ≦
Q
≦ 100
タイトルが同じ本は含まれない。
本のタイトル、著者、及びそれらに対するクエリの文字列の長さは 50 文字以下であり、含まれる文字はアルファベットの大文字と小文字のみである。大文字と小文字は区別される('a'と'A'は違う文字とみなす)。ただしクエリは
*
一文字のこともある。
本の出版日及びそれに対するクエリは
2014/07/31
のような形式で表され、西暦年 (4桁)/月(2桁)/日(2桁) という意味である。この例の場合は 2014 年 7 月 31 日を表す。
日付は 1970 年 1 月 1 日から 2037 年 12 月 31 日の範囲内である。
15 月 40 日のような無効な日付は入力されない。
Output
各クエリに対して、ヒットする本のタイトルを答えよ。 2 冊以上ヒットする場合は、1 行に 1 冊ずつ、入力された順番に全てのタイトルを出力せよ。 1 冊もヒットしない場合は 1 行も出力してはならない。クエリとクエリの間には空行を挟むこと。
Samples
Sample Input 1
6
antbook iwiWataKitamasa 2012/01/28
hogebook foo 2000/01/01
hugabook bar 2000/01/01
cheeterbook chokudai 2012/09/29
aojbook YutakaWatanabe 2014/06/28
piyobook buz 2000/01/01
4
a * * *
* chokudai * *
* Chokudai * *
* * 2014/01/01 2014/12/31
Sample Output 1
antbook
hugabook
aojbook

cheeterbook


aojbook
3 番目のクエリは、一見 2 番目のクエリと同じように見えるが、先頭の文字が大文字となっており、そのような名前のちょくだいさんは著者名として存在しないため、 1 行も出力してはならない。

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()

typedef pair<int, int> P;

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

struct Data{
    string title;
    string author;
    string date;
};

signed main(){
    int N, M;
    string t, n, df, dt;

    cin >> N;
    vector<Data> data;
    REP( i, N ){
        cin >> t >> n >> df;
        data.emplace_back( Data{ t, n, df } );
    }

    cin >> M;
    REP( i, M ){
        cin >> t >> n >> df >> dt;
        if( t == "*" ) t = ".*";
        if( n == "*" ) n = ".*";
        if( df == "*" ) df = "1970";
        if( dt == "*" ) dt = "2038";
        regex rt( t ), rn( n );

        REP( i, N ){
            if( regex_search( data[i].title, rt ) && regex_search( data[i].author, rn ) && data[i].date >= df && data[i].date <= dt ){
                cout << data[i].title << endl;
            }
        }
        if( i != M - 1 ) cout << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3344
final_rank: 6

code_snippet: #include<iostream>
#include<string>
#include<vector>
using namespace std;
#define MAX_N 100000
int N, Q; vector<int>vec, vec2;
string S[MAX_N][3], T[4];
bool Find(string U, string V) {
	int X = U.size(), Y = V.size();
	for (int i = 0; i <= X - Y; i++) {
		string W = U.substr(i, Y);
		if (W == V) {
			return true;
		}
	}
	return false;
}
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S[i][0] >> S[i][1] >> S[i][2];
	}
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		if (i >= 1) { cout << endl; }
		cin >> T[0] >> T[1] >> T[2] >> T[3];
		vec.clear(); vec2.clear();
		for (int j = 0; j < N; j++) {
			vec.push_back(j);
		}
		vec2 = vec;
		if (T[0] != "*") {
			vec2.clear();
			for (int j = 0; j < vec.size(); j++) {
				if (Find(S[vec[j]][0], T[0]) == true) {
					vec2.push_back(vec[j]);
				}
			}
		}
		vec.clear(); vec = vec2;
		if (T[1] != "*") {
			vec2.clear();
			for (int j = 0; j < vec.size(); j++) {
				if (Find(S[vec[j]][1], T[1]) == true) {
					vec2.push_back(vec[j]);
				}
			}
		}
		vec.clear(); vec = vec2;
		if (T[2] != "*") {
			vec2.clear();
			for (int j = 0; j < vec.size(); j++) {
				if (S[vec[j]][2] >= T[2]) {
					vec2.push_back(vec[j]);
				}
			}
		}
		vec.clear(); vec = vec2;
		if (T[3] != "*") {
			vec2.clear();
			for (int j = 0; j < vec.size(); j++) {
				if (S[vec[j]][2] <= T[3]) {
					vec2.push_back(vec[j]);
				}
			}
		}
		vec.clear(); vec = vec2; vec2.clear();
		for (int j = 0; j < vec.size(); j++) {
			cout << S[vec[j]][0] << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3600
final_rank: 7

code_snippet: /*
 * 2657.cc: Books
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

string ts[MAX_N], as[MAX_N];
int ds[MAX_N];

/* subroutines */

inline int ymd2n(string &s) {
  int y = atoi(s.substr(0, 4).c_str());
  int m = atoi(s.substr(5, 2).c_str());
  int d = atoi(s.substr(8, 2).c_str());
  return y * 10000 + m * 100 + d;
}

bool match(int i, string &t, string &a, string &fd, string &td) {
  if (t != "*" && ts[i].find(t) == string::npos) return false;
  if (a != "*" && as[i].find(a) == string::npos) return false;
  if (fd != "*") {
    int fdn = ymd2n(fd);
    if (fdn > ds[i]) return false;
  }
  if (td != "*") {
    int tdn = ymd2n(td);
    if (tdn < ds[i]) return false;
  }
  return true;
}

/* main */

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    string ymd;
    cin >> ts[i] >> as[i] >> ymd;
    ds[i] = ymd2n(ymd);
  }

  int q;
  cin >> q;

  for (int i = 0; i < q; i++) {
    string t, a, fd, td;
    cin >> t >> a >> fd >> td;

    if (i > 0) putchar('\n');
    
    for (int i = 0; i < n; i++)
      if (match(i, t, a, fd, td)) cout << ts[i] << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1240
final_rank: 1

code_snippet: #include <iostream>
#include <string>
#include <queue>
#define N 100
using namespace std;
int Change(string);
int Change_2(string);
int Search(string,string,int);
int Check(int,string,int);
int date[N];
string title[N],author[N];
int main(){
  int n,q,begin,end,need_check[4],r,flag,flag2,len,i,j,k;
  string indate,q_title,q_author,q_date_from,q_date_to,out;
  queue<string> Q;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> title[i] >> author[i] >> indate;
    date[i]=Change(indate);
  }
  cin >> q;
  flag2=0;
  for(i=0;i<q;i++){
    cin >> q_title >> q_author >> q_date_from >> q_date_to;
    if(q_date_from!="*") begin=Change(q_date_from);
    if(q_date_to!="*") end=Change(q_date_to);
    for(j=0;j<n;j++){
      for(k=0;k<4;k++) need_check[k]=0;
      if(q_title!="*"){
	need_check[0]=1;
	r=Search(q_title,"title",j);
	if(r==1) need_check[0]=0;
      }
      if(q_author!="*"){
	need_check[1]=1;
	r=Search(q_author,"author",j);
	if(r==1) need_check[1]=0;
      }
      if(q_date_from!="*"){
	need_check[2]=1;
	r=Check(begin,"from",j);
	if(r==1) need_check[2]=0;
      }
      if(q_date_to!="*"){
	need_check[3]=1;
	r=Check(end,"to",j);
	if(r==1) need_check[3]=0;
      }
      flag=0;
      for(k=0;k<4;k++){
	if(need_check[k]==1){
	  flag=1;
	  break;
	}
      }
      if(flag==0){
	Q.push(title[j]);
      }
    }
    len=Q.size();
    for(j=0;j<len;j++){
      out=Q.front();
      Q.pop();
      cout << out << endl;
    }
    if(i!=q-1) cout << endl;
  }
  return 0;
}
int Change(string s){
  int ret;
  string a,b,c,d;
  a=s.substr(0,4);
  b=s.substr(5,2);
  c=s.substr(8,2);
  ret=Change_2(a+b+c);
  return ret;
}
int Change_2(string s){
  int len=s.size(),ret=0,x=10,i=0;
  while(len){
    ret=ret*x+(s[i]-'0');
    i++;
    len--;
  }
  return ret;
}
int Search(string str,string c,int n){
  int len,len2,i,j,l,flag=0,cnt=0;
  if(c=="title"){
    len=title[n].size();
    len2=str.size();
    for(i=0;i<len;i++){
      l=i;
      for(j=0;j<len2;j++){
	if(str[j]==title[n][l]){
	  cnt++;
	  l++;
	}else{
	  cnt=0;
	}
	if(cnt==len2){
	  flag=1;
	  break;
	}
	if(l==len) break;
      }
      if(flag==1) break;
    }
    if(flag==1) return 1;
  }else{
    len=author[n].size();
    len2=str.size();
    for(i=0;i<len;i++){
      l=i;
      cnt=0;
      for(j=0;j<len2;j++){
	if(str[j]==author[n][l]){
	  cnt++;
	  l++;
	}else{
	  cnt=0;
	}
	if(cnt==len2){
	  flag=1;
	  break;
	}
	if(l==len) break;
      }
      if(flag==1) break;
    }
    if(flag==1) return 1;
  }
  return 0;
}
int Check(int y,string c,int n){
  if(c=="from"){
    if(y<=date[n]) return 1;
  }else{
    if(y>=date[n]) return 1;
  }
  return 0;
}
accuracy: 0.5576923076923077
time_ms: 10
memory_kb: 1256
final_rank: 9

code_snippet: #include <iostream>
#include <string>
#include <queue>
#define N 100
using namespace std;
int Change(string);
int Change_2(string);
int Search(string,string,int);
int Check(int,string,int);
int date[N];
string title[N],author[N];
int main(){
  int n,q,begin,end,need_check[4],r,flag,flag2,len,i,j,k;
  string indate,q_title,q_author,q_date_from,q_date_to,out;
  queue<string> Q;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> title[i] >> author[i] >> indate;
    date[i]=Change(indate);
  }
  cin >> q;
  flag2=0;
  for(i=0;i<q;i++){
    cin >> q_title >> q_author >> q_date_from >> q_date_to;
    if(q_date_from!="*") begin=Change(q_date_from);
    if(q_date_to!="*") end=Change(q_date_to);
    for(j=0;j<n;j++){
      for(k=0;k<4;k++) need_check[k]=0;
      if(q_title!="*"){
	need_check[0]=1;
	r=Search(q_title,"title",j);
	if(r==1) need_check[0]=0;
      }
      if(q_author!="*"){
	need_check[1]=1;
	r=Search(q_author,"author",j);
	if(r==1) need_check[1]=0;
      }
      if(q_date_from!="*"){
	need_check[2]=1;
	r=Check(begin,"from",j);
	if(r==1) need_check[2]=0;
      }
      if(q_date_to!="*"){
	need_check[3]=1;
	r=Check(end,"to",j);
	if(r==1) need_check[3]=0;
      }
      flag=0;
      for(k=0;k<4;k++){
	if(need_check[k]==1){
	  flag=1;
	  break;
	}
      }
      if(flag==0){
	Q.push(title[j]);
      }
    }
    if(flag2!=0&&Q.empty()!=1) cout << endl;
    if(Q.empty()==1) cout << endl;
    len=Q.size();
    for(j=0;j<len;j++){
      out=Q.front();
      Q.pop();
      cout << out << endl;
      flag2=1;
    }
  }
  return 0;
}
int Change(string s){
  int ret;
  string a,b,c,d;
  a=s.substr(0,4);
  b=s.substr(5,2);
  c=s.substr(8,2);
  ret=Change_2(a+b+c);
  return ret;
}
int Change_2(string s){
  int len=s.size(),ret=0,x=10,i=0;
  while(len){
    ret=ret*x+(s[i]-'0');
    i++;
    len--;
  }
  return ret;
}
int Search(string str,string c,int n){
  int len,len2,i,j,l,flag=0,cnt=0;
  if(c=="title"){
    len=title[n].size();
    len2=str.size();
    for(i=0;i<len;i++){
      l=i;
      for(j=0;j<len2;j++){
	if(str[j]==title[n][l]){
	  cnt++;
	  l++;
	}else{
	  cnt=0;
	}
	if(cnt==len2){
	  flag=1;
	  break;
	}
	if(l==len) break;
      }
      if(flag==1) break;
    }
    if(flag==1) return 1;
  }else{
    len=author[n].size();
    len2=str.size();
    for(i=0;i<len;i++){
      l=i;
      for(j=0;j<len2;j++){
	if(str[j]==author[n][l]){
	  cnt++;
	  l++;
	}else{
	  cnt=0;
	}
	if(cnt==len2){
	  flag=1;
	  break;
	}
	if(l==len) break;
      }
      if(flag==1) break;
    }
    if(flag==1) return 1;
  }
  return 0;
}
int Check(int y,string c,int n){
  if(c=="from"){
    if(y<=date[n]) return 1;
  }else{
    if(y>=date[n]) return 1;
  }
  return 0;
}
accuracy: 0.3076923076923077
time_ms: 10
memory_kb: 1260
final_rank: 11

code_snippet: #include <iostream>
#include <string>
#define N 100
using namespace std;
int Change(string);
int Change_2(string);
int Search(string,string,int);
int Check(int,string,int);
int date[N];
string title[N],author[N];
int main(){
  int n,q,begin,end,need_check[4],r,flag,i,j,k;
  string indate,q_title,q_author,q_date_from,q_date_to;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> title[i] >> author[i] >> indate;
    date[i]=Change(indate);
  }
  cin >> q;
  for(i=0;i<q;i++){
    if(i!=0) cout << endl;
    cin >> q_title >> q_author >> q_date_from >> q_date_to;
    if(q_date_from!="*") begin=Change(q_date_from);
    if(q_date_to!="*") end=Change(q_date_to);
    for(j=0;j<n;j++){
      for(k=0;k<4;k++) need_check[k]=0;
      if(q_title!="*"){
	need_check[0]=1;
	r=Search(q_title,"title",j);
	if(r==1) need_check[0]=0;
      }
      if(q_author!="*"){
	need_check[1]=1;
	r=Search(q_author,"author",j);
	if(r==1) need_check[1]=0;
      }
      if(q_date_from!="*"){
	need_check[2]=1;
	r=Check(begin,"from",j);
	if(r==1) need_check[2]=0;
      }
      if(q_date_to!="*"){
	need_check[3]=1;
	r=Check(end,"to",j);
	if(r==1) need_check[3]=0;
      }
      flag=0;
      for(k=0;k<4;k++){
	if(need_check[k]==1){
	  flag=1;
	  break;
	}
      }
      if(flag==0) cout << title[j] << endl;
    }
  }
  return 0;
}
int Change(string s){
  int ret;
  string a,b,c,d;
  a=s.substr(0,4);
  b=s.substr(5,2);
  c=s.substr(8,2);
  ret=Change_2(a+b+c);
  return ret;
}
int Change_2(string s){
  int len=s.size(),ret=0,x=10,i=0;
  while(len){
    ret=ret*x+(s[i]-'0');
    i++;
    len--;
  }
  return ret;
}
int Search(string str,string c,int n){
  int len,len2,i,j,l,flag=0,cnt=0;
  if(c=="title"){
    len=title[n].size();
    len2=str.size();
    for(i=0;i<len;i++){
      l=i;
      for(j=0;j<len2;j++){
	if(str[j]==title[n][l]){
	  cnt++;
	  l++;
	}else{
	  cnt=0;
	}
	if(cnt==len2){
	  flag=1;
	  break;
	}
	if(l==len) break;
      }
      if(flag==1) break;
    }
    if(flag==1) return 1;
  }else{
    len=author[n].size();
    len2=str.size();
    for(i=0;i<len;i++){
      l=i;
      for(j=0;j<len2;j++){
	if(str[j]==author[n][l]){
	  cnt++;
	  l++;
	}else{
	  cnt=0;
	}
	if(cnt==len2){
	  flag=1;
	  break;
	}
	if(l==len) break;
      }
      if(flag==1) break;
    }
    if(flag==1) return 1;
  }
  return 0;
}
int Check(int y,string c,int n){
  if(c=="from"){
    if(y<=date[n]) return 1;
  }else{
    if(y>=date[n]) return 1;
  }
  return 0;
}
accuracy: 0.3076923076923077
time_ms: 10
memory_kb: 1236
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;

string s[100],t[100];
int g[100];
int n,m;

int conv(string x){
    int a,b,c;
    char ig;
    stringstream ss(x);
    ss>>a>>ig>>b>>ig>>c;
    return a*10000+b*100+c;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        string a;
        cin>>s[i]>>t[i]>>a;
        g[i]=conv(a);
    }

    cin>>m;
    bool la=false;
    while(m--){
        if(la)cout<<endl;
        else la=true;
        string a,b,c,d;
        cin>>a>>b>>c>>d;
        for(int i=0;i<n;i++){
            bool flag=true;
            if(a!="*")if(s[i].find(a)==string::npos)flag=false;
            if(b!="*")if(t[i].find(b)==string::npos)flag=false;
            if(c!="*")if(conv(c)>g[i])flag=false;
            if(d!="*")if(conv(d)<g[i])flag=false;
            if(flag)cout<<s[i]<<endl;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1240
final_rank: 1

code_snippet: #include <bits/stdc++.h>

using namespace std;

namespace {
    int N;
    vector<string> T, A, D;
    int Q;

    const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int days_leap[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    bool is_leap(int y) {
        if (y % 400 == 0) return true;
        if (y % 100 == 0) return false;
        if (y % 4 == 0) return true;
        return false;
    }

    int date(const string& s) {
        int y, m, d;
        sscanf(s.c_str(), "%d/%d/%d", &y, &m, &d);
        int ret = 365 * y;
        ret += (y / 400) * 97;
        for (int i = 0; i < y % 400; i++) {
            if (is_leap(i)) ret++;
        }
        bool l = is_leap(y);
        for (int i = 1; i < m; i++) ret += (l ? days_leap : days)[i];
        ret += d;
        return ret;
    }

    bool check(const string& s, const string& key) {
        if (key == "*") return true;
        return s.find(key) != string::npos;
    }

    void query(const string& t, const string& a, const string& froms, const string& tos) {
        int from, to;
        if (froms == "*") from = 0;
        else from = date(froms);
        if (tos == "*") to = date("2040/01/01");
        else to = date(tos);

        for (int i = 0; i < N; i++) {
            if (!check(T[i], t)) continue;
            if (!check(A[i], a)) continue;
            int d = date(D[i]);
            if (!(from <= d && d <= to)) continue;
            cout << T[i] << endl;
        }
    }

    void solve() {
        cin >> N;
        T.resize(N); A.resize(N); D.resize(N);
        for (int i = 0; i < N; i++) {
            cin >> T[i] >> A[i] >> D[i];
        }
        cin >> Q;
        for (int i = 0; i < Q; i++) {
            string t, a, from, to;
            cin >> t >> a >> from >> to;
            if (i != 0) cout << endl;
            query(t, a, from, to);
        }
    }
}

int main() {
    solve();
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1296
final_rank: 8

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
 
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
   
using namespace std;
   
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
   
static const double EPS = 1e-8;
   
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

class Book {
private:
  string title;
  string author;
  string date;

  int date2sec(string date){
    vector<string> elements;
    string tmp = "";
    for(int i = 0; i < date.size(); i++){
      if(date[i] == '/'){
        elements.push_back(tmp);
        tmp = "";
        continue;
      }
      tmp += date[i];
    }
    elements.push_back(tmp);
    
    return 365 * (atoi(elements[0].c_str()) - 1970)
      + atoi(elements[1].c_str()) * 31
      + atoi(elements[2].c_str());
  }

public:
  Book(string title, string author, string date) {
    this->title = title;
    this->author = author;
    this->date = date;
  }

  bool match_title(string query){
    if(query == "*") return true;
    for(int i = 0; i + query.size() <= title.size(); i++){
      if(title.substr(i,query.size()) == query) return true;
    }
    return false;
  }

  bool match_author(string query){
    if(query == "*") return true;
    for(int i = 0; i + query.size() <= author.size(); i++){
      if(author.substr(i,query.size()) == query) return true;
    }
    return false;
  }

  bool match_date(string from,string to) {
    int my_sec = date2sec(date);
    if(from != "*" && my_sec < date2sec(from)) return false;
    if(to != "*" && my_sec > date2sec(to)) return false;
    return true;
  }

  string get_title() const {
    return title;
  }
};

int main(){
  int num_of_books;
  int num_of_queries;
  while(~scanf("%d",&num_of_books)){
    vector<Book> books;
    for(int book_i = 0; book_i < num_of_books; book_i++){
      string title,author,date;
      cin >> title >> author >> date;
      books.push_back(Book(title,author,date));
    }
    scanf("%d",&num_of_queries);
    for(int query_i = 0; query_i < num_of_queries; query_i++){
      string title,author,from,to;
      cin >> title >> author >> from >> to;
      for(int book_i = 0; book_i < num_of_books; book_i++){
        if(books[book_i].match_title(title)
           && books[book_i].match_author(author)
           && books[book_i].match_date(from,to)){
          cout << books[book_i].get_title() << endl;
        }
      }
      if(query_i != num_of_queries -1){
        cout << endl;
      }
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1276
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

class Book{
public:
  string title,author;
  int date;
};

int getDate(string &s){
  for(int i = 0 ; i < (int)s.size() ; i++){
    if(s[i] == '/'){
      s[i] = ' ';
    }
  }
  int y,m,d;
  stringstream ss(s);
  ss >> y; ss >> m; ss >> d;
  return y*10000 + m*100 + d;
}

int main(){
  int N;
  string str;
  bool blank = false;
  cin >> N;
  vector<Book> books(N);
  for(int i = 0 ; i < N ; i++){
    cin >> books[i].title >> books[i].author >> str;
    books[i].date = getDate(str);
  }
  int Q;
  cin >> Q;
  while(Q--){
    if(blank){ cout << endl; }
    blank = true;
    string s[4];
    int S = 0;
    for(int i = 0 ; i < 4 ; i++){
      cin >> s[i];
      if(s[i] == "*"){
        S |= (1<<i);
      }
    }
    vector<string> res;
    for(int i = 0 ; i < N ; i++){
      bool ok = true;
      for(int j = 0 ; j < 4 ; j++){
        if(S >> j & 1){ continue; }
        if(j == 0){
          if(books[i].title.find(s[j]) == string::npos){
            ok = false;
          }
        }else if(j == 1){
          if(books[i].author.find(s[j]) == string::npos){
            ok = false;
          }
        }else if(j == 2){
          int date = getDate(s[j]);
          if(date > books[i].date){
            ok = false;
          }
        }else{
          int date = getDate(s[j]);
          if(books[i].date > date){
            ok = false;
          }
        }
      }
      if(ok){
        res.push_back(books[i].title);
      }
    }
    for(auto x : res){
      cout << x << endl;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1252
final_rank: 3

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0
#define EPS 1e-8

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.B";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}

struct BOOK{
	string title;
	string auther;
	string date;
	ll datenum;
};

bool operator==(const BOOK &a, const BOOK &b ){
	return (a.title == b.title && a.auther == b.auther && a.date == b.date );
}

BOOK book[105];

const int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const int leap[] = { 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036 };

// 1970/01/01 からの経過日時
ll calc_date (string d ){

	rep (i, d.length() ) if (!isdigit(d[i] ) )  d[i] = ' ';
	stringstream ss(d );

	int year, month, date;
	ss >> year >> month >> date;
	ll res = 0LL;

	rep (i, sizeof(leap)/sizeof(leap[0] ) ){
		if (leap[i] < year ) res++;
		else
		if (leap[i] == year && month >= 3 ) res++;
	} 
	year -= 1970;
	month -= 1;
	res += (ll)365*year;
	rep (i, month ) res += (ll)days[i];
	res += (ll)date;

	return res;
}

void disp_book (BOOK b ){
	cerr << b.title << endl;
	cerr << b.auther << endl;
	cerr << b.date << endl;
	cerr << b.datenum << endl;
}

int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	rep (i, 105 ) book[i].title = "", book[i].auther = "", book[i].date = "", book[i].datenum = 0;
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	rep (i, n ){
		cin >> book[i].title >> book[i].auther >> book[i].date;
		book[i].datenum = calc_date (book[i].date);
//		disp_book (book[i] );
	} // end rep

	int q; cin >> q;
	while (q-- ){
		string q_title = "", q_auther = "", q_date_from = "1970/01/01", q_date_to = "2037/12/31";
		string q_t, q_a, q_d_f, q_d_t;
		vector<BOOK> search[3];
		rep (k, 3 ) search[k].clear();

		cin >> q_t >> q_a >> q_d_f >> q_d_t;
		if (q_t != "*" ) q_title = q_t;
		if (q_a != "*" ) q_auther = q_a;
		if (q_d_f != "*" ) q_date_from = q_d_f;
		if (q_d_t != "*" ) q_date_to = q_d_t;

		if (!q_title.empty() ){
			rep (i, n ){
				string curr = book[i].title;
				if (curr.find (q_title ) != string::npos ) search[0].push_back (book[i] );
			} // end if
		}else{
			rep (i, n ) search[0].push_back (book[i] );
		} // end if

		if (!q_auther.empty() ){
			rep (i, n ) if (book[i].auther == q_auther ) search[1].push_back (book[i] );
		}else{
			rep (i, n ) search[1].push_back (book[i] );
		} // end if

		ll from = calc_date (q_date_from );
		ll to   = calc_date (q_date_to );
		rep (i, n ){
			ll curr = book[i].datenum;
			if (from <= curr && curr < to ) search[2].push_back (book[i] );	
//			
		} // end rep

		vector<string> res; res.clear();
		rep (i, search[0].size() ){
			rep (j, search[1].size() ){
				rep (k, search[2].size() ){
					if (search[0][i] == search[1][j] && search[1][j] == search[2][k] ){
						BOOK ans = search[0][i];
						res.push_back (ans.title );
					} // end if
				} // end rep
			} // end rep
		} // end rep
	

		if (!res.empty() ){
			rep (i, res.size() ){
				cout << res[i] << endl;
			} // end rep
		} // end if
		if (q != 0 ) cout << endl;
	} // end while	
		
		
#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif			
	return 0;
}
accuracy: 0.038461538461538464
time_ms: 20
memory_kb: 1280
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0
#define EPS 1e-8

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.B";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}

struct BOOK{
	string title;
	string auther;
	string date;
	ll datenum;
};

bool operator==(const BOOK &a, const BOOK &b ){
	return (a.title == b.title && a.auther == b.auther && a.date == b.date );
}

BOOK book[105];

const int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const int leap[] = { 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036 };

// 1970/01/01 からの経過日時
ll calc_date (string d ){

	rep (i, d.length() ) if (!isdigit(d[i] ) )  d[i] = ' ';
	stringstream ss(d );

	int year, month, date;
	ss >> year >> month >> date;
	ll res = 0LL;

	rep (i, sizeof(leap)/sizeof(leap[0] ) ){
		if (leap[i] < year ) res++;
		else
		if (leap[i] == year && month >= 3 ) res++;
	} 
	year -= 1970;
	month -= 1;
	res += (ll)365*year;
	rep (i, month ) res += (ll)days[i];
	res += (ll)date;

	return res;
}

void disp_book (BOOK b ){
	cerr << b.title << endl;
	cerr << b.auther << endl;
	cerr << b.date << endl;
	cerr << b.datenum << endl;
}

int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	rep (i, 105 ) book[i].title = "", book[i].auther = "", book[i].date = "", book[i].datenum = 0;
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	rep (i, n ){
		cin >> book[i].title >> book[i].auther >> book[i].date;
		book[i].datenum = calc_date (book[i].date);
//		disp_book (book[i] );
	} // end rep

	int q; cin >> q;
	while (q-- ){
		string q_title = "", q_auther = "", q_date_from = "1970/01/01", q_date_to = "2037/12/31";
		string q_t, q_a, q_d_f, q_d_t;
		vector<BOOK> search[3];
		rep (k, 3 ) search[k].clear();

		cin >> q_t >> q_a >> q_d_f >> q_d_t;
		if (q_t != "*" ) q_title = q_t;
		if (q_a != "*" ) q_auther = q_a;
		if (q_d_f != "*" ) q_date_from = q_d_f;
		if (q_d_t != "*" ) q_date_to = q_d_t;

		if (!q_title.empty() ){
			rep (i, n ){
				string curr = book[i].title;
				if (curr.find (q_title ) != string::npos ) search[0].push_back (book[i] );
			} // end if
		}else{
			rep (i, n ) search[0].push_back (book[i] );
		} // end if

		if (!q_auther.empty() ){
			rep (i, n ) if (book[i].auther == q_auther ) search[1].push_back (book[i] );
		}else{
			rep (i, n ) search[1].push_back (book[i] );
		} // end if

		ll from = calc_date (q_date_from );
		ll to   = calc_date (q_date_to );
		rep (i, n ){
			ll curr = book[i].datenum;
			if (from <= curr && curr <= to ) search[2].push_back (book[i] );	
//			if ( (from < curr || abs (from - curr ) < EPS ) && (curr < to || abs (to - curr ) < EPS ) ) search[2].push_back (book[i] );
		} // end rep

		vector<string> res; res.clear();
		rep (i, search[0].size() ){
			rep (j, search[1].size() ){
				rep (k, search[2].size() ){
					if (search[0][i] == search[1][j] && search[1][j] == search[2][k] ){
						BOOK ans = search[0][i];
						res.push_back (ans.title );
					} // end if
				} // end rep
			} // end rep
		} // end rep
	

		if (!res.empty() ){
			rep (i, res.size() ){
				cout << res[i] << endl;
			} // end rep
		} // end if
		if (q != 0 ) cout << endl;
	} // end while	
		
		
#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif			
	return 0;
}
accuracy: 0.038461538461538464
time_ms: 20
memory_kb: 1280
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0
#define EPS 1e-8

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.B";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}

struct BOOK{
	string title;
	string auther;
	string date;
	ll datenum;
};

bool operator==(const BOOK &a, const BOOK &b ){
	return (a.title == b.title && a.auther == b.auther && a.date == b.date );
}

BOOK book[105];

const int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const int leap[] = { 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036 };

// 1970/01/01 からの経過日時
ll calc_date (string d ){

	rep (i, d.length() ) if (!isdigit(d[i] ) )  d[i] = ' ';
	stringstream ss(d );

	int year, month, date;
	ss >> year >> month >> date;
	ll res = 0LL;

	rep (i, sizeof(leap)/sizeof(leap[0] ) ){
		if (leap[i] < year ) res++;
		else
		if (leap[i] == year && month >= 3 ) res++;
	} 
	year -= 1900;
	month -= 1;
	res += (ll)365*year;
	rep (i, month ) res += (ll)days[i];
	res += (ll)date;

	return res;
}

void disp_book (BOOK b ){
	cerr << b.title << endl;
	cerr << b.auther << endl;
	cerr << b.date << endl;
	cerr << b.datenum << endl;
}

int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	rep (i, 105 ) book[i].title = "", book[i].auther = "", book[i].date = "", book[i].datenum = 0;
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	rep (i, n ){
		cin >> book[i].title >> book[i].auther >> book[i].date;
		book[i].datenum = calc_date (book[i].date);
//		disp_book (book[i] );
	} // end rep

	int q; cin >> q;
	while (q-- ){
		string q_title = "", q_auther = "", q_date_from = "1970/01/01", q_date_to = "2037/12/31";
		string q_t, q_a, q_d_f, q_d_t;
		vector<BOOK> search[3];
		rep (k, 3 ) search[k].clear();

		cin >> q_t >> q_a >> q_d_f >> q_d_t;
		if (q_t != "*" ) q_title = q_t;
		if (q_a != "*" ) q_auther = q_a;
		if (q_d_f != "*" ) q_date_from = q_d_f;
		if (q_d_t != "*" ) q_date_to = q_d_t;

		if (!q_title.empty() ){
			rep (i, n ){
				string curr = book[i].title;
				if (curr.find (q_title ) != string::npos ) search[0].push_back (book[i] );
			} // end if
		}else{
			rep (i, n ) search[0].push_back (book[i] );
		} // end if

		if (!q_auther.empty() ){
			rep (i, n ) if (book[i].auther == q_auther ) search[1].push_back (book[i] );
		}else{
			rep (i, n ) search[1].push_back (book[i] );
		} // end if

		ll from = calc_date (q_date_from );
		ll to   = calc_date (q_date_to );
		rep (i, n ){
			ll curr = book[i].datenum;
			if (from <= curr && curr <= to ) search[2].push_back (book[i] );	
//			if ( (from < curr || abs (from - curr ) < EPS ) && (curr < to || abs (to - curr ) < EPS ) ) search[2].push_back (book[i] );
		} // end rep

		vector<string> res; res.clear();
		rep (i, search[0].size() ){
			rep (j, search[1].size() ){
				rep (k, search[2].size() ){
					if (search[0][i] == search[1][j] && search[1][j] == search[2][k] ){
						BOOK ans = search[0][i];
						res.push_back (ans.title );
					} // end if
				} // end rep
			} // end rep
		} // end rep
	

		if (!res.empty() ){
			rep (i, res.size() ){
				cout << res[i] << endl;
			} // end rep
		} // end if
		if (q != 0 ) cout << endl;
	} // end while	
		
		
#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif			
	return 0;
}
accuracy: 0.038461538461538464
time_ms: 20
memory_kb: 1280
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0
#define EPS 1e-8

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.B";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}

struct BOOK{
	string title;
	string auther;
	string date;
	ll datenum;
};

bool operator==(const BOOK &a, const BOOK &b ){
	return (a.title == b.title && a.auther == b.auther && a.date == b.date );
}

BOOK book[105];

const int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const int leap[] = { 1904, 1908, 1912, 1916, 1920, 1924, 1928, 1932, 1936, 1940, 1944, 1948, 1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036 };

// 1970/01/01 からの経過日時
ll calc_date (string d ){

	rep (i, d.length() ) if (!isdigit(d[i] ) )  d[i] = ' ';
	stringstream ss(d );

	int year, month, date;
	ss >> year >> month >> date;
	ll res = 0LL;

	rep (i, sizeof(leap)/sizeof(leap[0] ) ){
		if (leap[i] < year ) res++;
		else
		if (leap[i] == year && month >= 3 ) res++;
	} 
	year -= 1900;
	month -= 1;
	res += (ll)365*year;
	rep (i, month ) res += (ll)days[i];
	res += (ll)date;

	return res;
}

void disp_book (BOOK b ){
	cerr << b.title << endl;
	cerr << b.auther << endl;
	cerr << b.date << endl;
	cerr << b.datenum << endl;
}

int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	rep (i, 105 ) book[i].title = "", book[i].auther = "", book[i].date = "", book[i].datenum = 0;
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	rep (i, n ){
		cin >> book[i].title >> book[i].auther >> book[i].date;
		book[i].datenum = calc_date (book[i].date);
//		disp_book (book[i] );
	} // end rep

	int q; cin >> q;
	while (q-- ){
		string q_title = "", q_auther = "", q_date_from = "1970/01/01", q_date_to = "2037/12/31";
		string q_t, q_a, q_d_f, q_d_t;
		vector<BOOK> search[3];
		rep (k, 3 ) search[k].clear();

		cin >> q_t >> q_a >> q_d_f >> q_d_t;
		if (q_t != "*" ) q_title = q_t;
		if (q_a != "*" ) q_auther = q_a;
		if (q_d_f != "*" ) q_date_from = q_d_f;
		if (q_d_t != "*" ) q_date_to = q_d_t;

		if (!q_title.empty() ){
			rep (i, n ){
				string curr = book[i].title;
				if (curr.find (q_title ) != string::npos ) search[0].push_back (book[i] );
			} // end if
		}else{
			rep (i, n ) search[0].push_back (book[i] );
		} // end if

		if (!q_auther.empty() ){
			rep (i, n ) if (book[i].auther == q_auther ) search[1].push_back (book[i] );
		}else{
			rep (i, n ) search[1].push_back (book[i] );
		} // end if

		ll from = calc_date (q_date_from );
		ll to   = calc_date (q_date_to );
		rep (i, n ){
			ll curr = book[i].datenum;
			if (from <= curr && curr <= to ) search[2].push_back (book[i] );	
//			if ( (from < curr || abs (from - curr ) < EPS ) && (curr < to || abs (to - curr ) < EPS ) ) search[2].push_back (book[i] );
		} // end rep

		vector<string> res; res.clear();
		rep (i, search[0].size() ){
			rep (j, search[1].size() ){
				rep (k, search[2].size() ){
					if (search[0][i] == search[1][j] && search[1][j] == search[2][k] ){
						BOOK ans = search[0][i];
						res.push_back (ans.title );
					} // end if
				} // end rep
			} // end rep
		} // end rep
	

		if (!res.empty() ){
			rep (i, res.size() ){
				cout << res[i] << endl;
			} // end rep
		} // end if
		if (q != 0 ) cout << endl;
	} // end while	
		
		
#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif			
	return 0;
}
accuracy: 0.038461538461538464
time_ms: 20
memory_kb: 1280
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0
#define EPS 1e-8

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.B";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}

struct BOOK{
	string title;
	string auther;
	string date;
	ll datenum;
};

bool operator==(const BOOK &a, const BOOK &b ){
	return (a.title == b.title && a.auther == b.auther && a.date == b.date );
}

BOOK book[105];

const int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

ll calc_date (string d ){

	rep (i, d.length() ) if (!isdigit(d[i] ) )  d[i] = ' ';
	stringstream ss(d );

	int year, month, date;
	ss >> year >> month >> date;
	year -= 1900;
	month -= 1;
	ll res = 0LL;
	res += (ll)365*year;
	rep (i, month ) res += (ll)days[i];
	res += (ll)date;

	return res;
}

void disp_book (BOOK b ){
	cerr << b.title << endl;
	cerr << b.auther << endl;
	cerr << b.date << endl;
	cerr << b.datenum << endl;
}

int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	rep (i, 105 ) book[i].title = "", book[i].auther = "", book[i].date = "", book[i].datenum = 0;
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	rep (i, n ){
		cin >> book[i].title >> book[i].auther >> book[i].date;
		book[i].datenum = calc_date (book[i].date);
//		disp_book (book[i] );
	} // end rep

	int q; cin >> q;
	while (q-- ){
		string q_title = "", q_auther = "", q_date_from = "1970/01/01", q_date_to = "2037/12/31";
		string q_t, q_a, q_d_f, q_d_t;
		vector<BOOK> search[3];
		rep (k, 3 ) search[k].clear();

		cin >> q_t >> q_a >> q_d_f >> q_d_t;
		if (q_t != "*" ) q_title = q_t;
		if (q_a != "*" ) q_auther = q_a;
		if (q_d_f != "*" ) q_date_from = q_d_f;
		if (q_d_t != "*" ) q_date_to = q_d_t;

		if (!q_title.empty() ){
			rep (i, n ){
				string curr = book[i].title;
				if (curr.find (q_title ) != string::npos ) search[0].push_back (book[i] );
			} // end if
		}else{
			rep (i, n ) search[0].push_back (book[i] );
		} // end if

		if (!q_auther.empty() ){
			rep (i, n ) if (book[i].auther == q_auther ) search[1].push_back (book[i] );
		}else{
			rep (i, n ) search[1].push_back (book[i] );
		} // end if

		ll from = calc_date (q_date_from );
		ll to   = calc_date (q_date_to );
		rep (i, n ){
			ll curr = book[i].datenum;
			if (from <= curr && curr <= to ) search[2].push_back (book[i] );	
//			if ( (from < curr || abs (from - curr ) < EPS ) && (curr < to || abs (to - curr ) < EPS ) ) search[2].push_back (book[i] );
		} // end rep

		vector<string> res; res.clear();
		rep (i, search[0].size() ){
			rep (j, search[1].size() ){
				rep (k, search[2].size() ){
					if (search[0][i] == search[1][j] && search[1][j] == search[2][k] ){
						BOOK ans = search[0][i];
						res.push_back (ans.title );
					} // end if
				} // end rep
			} // end rep
		} // end rep
	

		if (!res.empty() ){
			rep (i, res.size() ){
				cout << res[i] << endl;
			} // end rep
		} // end if
		if (q != 0 ) cout << endl;
	} // end while	
		
		
#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif			
	return 0;
}
accuracy: 0.038461538461538464
time_ms: 20
memory_kb: 1280
final_rank: 12

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) ((a).begin(),(a).end())
using namespace std;
typedef vector<int> vi;

vi toVec(string s){
  rep(i,s.size()){
    if(s[i] == '/')s[i] = ' ';
  }
  stringstream ss(s);
  vi res;
  int tmp;
  while(ss >> tmp){
    res.push_back(tmp);
  }
  return res;
}


int main(){
  vi start = toVec("0000/00/00");
  vi last = toVec("9999/99/99");

  int n,q;
  cin >> n;
  vector<string> bn(n),ba(n),bd(n);
  vector<vi> bv(n);

  rep(i,n){
    cin >> bn[i] >> ba[i] >> bd[i];
    bv[i] = toVec(bd[i]);
  }

  cin >> q;
  rep(i,q){
    string qn,qa,qf,qt;
    vi qvf,qvt;
    cin >> qn >> qa >> qf >> qt;
    
    rep(j,n){
      bool f = true;
      if(qn!="*"){
	f &= (bn[j].find(qn)!=string::npos);
      }

      if(qa!="*"){
	f &= (ba[j].find(qa)!=string::npos);
      }

      if(qf!="*")qvf = toVec(qf);
      else qvf = start;
      if(qt!="*")qvt = toVec(qt);
      else qvt = last;
      f &= (qvf <= bv[j] && bv[j] <= qvt);
      
      if(f)cout << bn[j] << endl;
    }
    if(i<q-1)cout << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1272
final_rank: 4