include iostream include vector include string std vector std vector s

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <vector>
#include <string>
std::vector< std::vector<std::string> > db;
std::vector<std::string> query;
std::vector<unsigned int> resultvec;
unsigned int dbsize = 0;
unsigned int rownum = 0;
unsigned int querynum = 0;
void showDb(){
for(unsigned int i=0; i<db.size(); i++){
for(unsigned int j=0; j<db[i].size(); j++)
{
std::cout<<db[i][j]<<" ";
}
std::cout<<std::endl;
}
}
void showQuery(){
for(unsigned int i=0; i<query.size(); i++){
std::cout<<query[i]<<std::endl;
}
}
bool compare(std::vector< std::string > op1, std::vector<std::string> op2){
if(op1.size()!=op2.size())
return false;
for(unsigned int i=0; i<op1.size(); i++){
if(op2[i].size()<op1[i].size())
return false;
for(unsigned int j=0; j<op1[i].size(); j++){
if(op1[i][j]!=op2[i][j])
return false;
}
}
return true;
}
int makeQuery(int* result){
for(unsigned int i=0; i<db.size(); i++){
if(compare(query, db[i]))
(*result)++;
}
return 0;
}
int addLetter(const unsigned int fieldnum, char letter){
if(fieldnum>=query.size())
return 1;
query[fieldnum].push_back(letter);
return 0;
}
int delLetter(const unsigned int fieldnum){
if(fieldnum>=query.size())
return 1;
if(query[fieldnum].size()!=0)
query[fieldnum].erase(query[fieldnum].begin()+query[fieldnum].size()-1);
return 0;
}
int main()
{
std::cin>>dbsize>>rownum;
for(unsigned int i=0; i<dbsize; i++){
std::vector<std::string> newelement;
for(unsigned int j=0; j<rownum; j++){
std::string newword = "";
std::cin>>newword;
newelement.push_back(newword);
}
db.push_back(newelement);
}
for(unsigned int i=0; i<rownum; i++){
query.push_back("");
}
std::cin>>querynum;
for(unsigned int i=0; i<querynum; i++)
{
unsigned int fieldnum = 0;
char action = ' ';
char letter = ' ';
int result = 0;
std::cin>>fieldnum>>action;
switch (action){
case '+':
std::cin>>letter;
addLetter(fieldnum-1, letter);
break;
case '-':
if(delLetter(fieldnum-1)){
//std::cout<<"error"<<std::endl;
}
break;
}
//showQuery();
makeQuery(&result);
resultvec.push_back(result);
//std::cout<<result<<std::endl;
}
for(unsigned int i=0; i<resultvec.size(); i++){
std::cout<<resultvec[i]<<std::endl;
}
//showDb();
return 0;
}