题目描述

在数据库的操作过程中,我们进场会遇到检索操作。这个题目的任务是完成一些特定格式的检索,并输出符合条件的数据库中的所有结果。 
我们现在有一个数据库,维护了学生的姓名(Name),性别(Sex)以及出生日期(Birthday)。其中,Name项是长度不超过30的字符串,只可能包含大小写字母,没有空格;Sex项进可能为‘Male’或者‘Female’(不含引号);Birthday项以yyy/mm/dd的格式存储,如:1990/01/01, 
1991/12/31,等等。 
每个查询所可能包含的条件如下: 
Name=‘REQUIRED_NAME’,查询姓名为REQUIRED_NAME的学生,其中REQUIRED_NAME为长度在1到30之间的字符串; 
Sex=‘Male’或Sex=‘Female’,查询性别为男/女的学生; 
Birthday=‘yyy/mm/dd’,查询出生年/月/日为特定值的学生。如果其中某项为’’,则说明该项不受限制。例如,‘1990/06/’表示1990年6月出生,‘/03/’表示出生月份为3月。 
给定数据库的所有表项以及若干条查询,你需要对每条查询输出它返回的结果。 

输入

输入包含多组测试数据。输入的第一行为测试数据的组数T(1<=T<=50)。 
对于每组测试数据,第一行是两个整数N和M(N,M<=500),分别表示数据的数量以及查询的数量。 
接下来N行,每行以Name Sex Birthday的形式给出每个学生的信息。 
没下来M行,每行给出若干条限制条件,以空格隔开。条件以Name Sex Birthday的顺序给出(如果存在),且每种限制条件最多只出现一次。 

输出

对于每条查询,按照输入的顺序输出符合条件的学生姓名,每个一行。如果没有符合查询的信息,则输出一行NULL。

样例输入

1
5
6
Michael Male 1990/02/28
Amy Female 1992/04/03
Tom Male 1991/12/15
Lynn Female 1991/04/09
Zheng Male 1990/04/20
Name='Amy'
Name='Betty'
Sex='Female' Birthday='*/04/09'
Sex='Female' Birthday='*/*/*'
Name='Michael' Sex='Female'
Name='Michael' Sex='Male' Birthday='1990/02/*'

样例输出

Amy
NULL
Lynn
Amy
Lynn
NULL
Michael

来源

2014软院D题

。。。。。TLE了,具体原因是string用得太多,应改为char数组,TLE的版本。。。。↓

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
using namespace std;
struct dog
{
string sex;
string birthday;
};
map<string,dog> donser;
bool deal(string a,string b)
{
string temp="/";
int pos1=a.find(temp[]);
int pos2=b.find(temp[]);
if(pos1==pos2)
{
string s1=a.substr(,pos1);
string s2=b.substr(,pos2);
if(s1!=s2)
return false;
}
a.erase(,pos1+);
b.erase(,pos2+);
pos1=a.find(temp[]);
pos2=b.find(temp[]);
if(pos1==pos2)
{
string s1=a.substr(,pos1);
string s2=b.substr(,pos2);
if(s1!=s2)
return false;
}
a.erase(,pos1+);
b.erase(,pos2+);
if(a.size()==b.size())
{
if(a!=b)
return false;
}
return true;
}
int main()
{
int tes,m,n;
//freopen("test.out","w",stdout);
while(~scanf("%d",&tes))
{
while(tes--)
{
cin>>m>>n;
while(m--)
{
string a,b,c;
cin>>a>>b>>c;
donser[a].sex=b;
donser[a].birthday=c;
}
cin.get();
while(n>)
{
n--;
string str,temp="a'a",c_name="",c_sex="",c_birth="";
bool lable=false,named=false,sexd=false,birthd=false;
getline(cin,str);
if(str[]=='N')
{
str.erase(,);
int pos=str.find(temp[]);
c_name=str.substr(,pos);
named=true;
str.erase(,pos+);
if( donser.find(c_name)==donser.end())
{
cout<<"NULL"<<endl;
continue;
}
if(str.size()>)
str.erase(,);
}
if(str.size()>&&str[]=='S')
{
str.erase(,);
int pos=str.find(temp[]);
c_sex=str.substr(,pos);
sexd=true;
str.erase(,pos+);
if(str.size()>)
str.erase(,);
}
if(str.size()>&&str[]=='B')
{
str.erase(,);
int pos=str.find(temp[]);
c_birth=str.substr(,pos);
birthd=true;
str="";
}
if(named)
{
if((donser[c_name].sex==c_sex||sexd==false)&&(deal(donser[c_name].birthday,c_birth)||birthd==false))
cout<<c_name<<endl;
else
cout<<"NULL"<<endl;
}
else
{
map<string,dog>::iterator it;
for(it=donser.begin();it!=donser.end();it++)
{
if((it->second.sex==c_sex||sexd==false)&&(deal(it->second.birthday,c_birth)||birthd==false))
{
cout<<it->first<<endl;
lable=true;
}
}
if(lable==false)
cout<<"NULL"<<endl;
}
}
donser.clear();
}
}
return ;
}

最新文章

  1. 使用apache ftpserver搭建ftp服务器
  2. Java RSA 分段加解密
  3. GIT之二 基础篇(1)
  4. PC上安装MAC X Lion
  5. 应该始终以PreparedStatement代替Statement
  6. 【C#设计模式——创建型模式】工场方法模式
  7. poj1256(全排列stl)
  8. 解决(防止)DDOS攻击的另一种思想
  9. Xcode 中的断言
  10. [CSS] input样式定制
  11. altiumdesigner的基本你操作
  12. import os, glob, fnmatch--Python os/glob/fnmatch主要函数总结
  13. k8s对接ceph存储
  14. js开发相关
  15. 一种BCD码转换的算法
  16. Mayor&#39;s posters---poj2528线段树、离散化
  17. Thinkphp5 引入第三方类库的方法
  18. Json.Net组件指定/忽略序列化字段属性技巧知识点
  19. C++ 有用的网站
  20. Java代码生成器CodeX4J介绍

热门文章

  1. verilog behavioral modeling--branch statement
  2. 【mysql】返回非空值 COALESCE 用法
  3. 【支付宝支付】扫码付和app支付,回调验证签名失败问题
  4. PyCharm学习笔记(二) 调试配置
  5. 对linux中source,fork,exec的理解以及case的 使用
  6. 00051_static关键字
  7. python-selenium使用send_keys()方法写中文报错的解决方法
  8. 四、harbor实践之初识harbor
  9. 对于一棵二叉树,请设计一个算法,创建含有某一深度上所有结点的链表。 给定二叉树的根结点指针TreeNode* root,以及链表上结点的深度,请返回一个链表ListNode,代表该深度上所有结点的值,请按树上从左往右的顺序链接,保证深度不超过树的高度,树上结点的值为非负整数且不超过100000。
  10. 常州模拟赛d4t2 陶陶摘苹果