实在找不出问题,那个错误报的太诡异了,又厉害大神可以帮忙找一下;
错误c2678;
参考了网上一位大神挺多的;
代码如下:
#include<stdio.h>
#include<iostream>
#include<string>
#include<sstream>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
int n, m;
map<string, int>str;
vector<set<int>>k[100];
vector<string>str1;
vector<string>ori;
int id(string s1) {
if (str.count(s1)) return str[s1];
str1.push_back(s1);
str[s1] = str1.size() - 1;
return str[s1];
}
void find_print(string s1) {
int id1 = id(s1);
for (int j = 0; j < n; j++) {
if (find(k[j].begin(), k[j].end(), id1) != k[j].end()) {
cout << ori[j] << endl;
}
}
}
void find_print1(string s1, string s2) {
int id1 = id(s1), id2 = id(s2);
for (int j = 0; j < n; j++) {
if (find(k[j].begin(), k[j].end(), id1) != k[j].end() && find(k[j].begin(), k[j].end(), id2) != k[j].end()) {
cout << ori[j] << endl;
}
}
}
void find_print2(string s1, string s2) {
int id1 = id(s1), id2 = id(s2);
for (int j = 0; j < n; j++) {
if (find(k[j].begin(), k[j].end(), id1) != k[j].end() || find(k[j].begin(), k[j].end(), id2) != k[j].end()) {
cout << ori[j] << endl;
}
}
}
int main() {
cin >> n >> m;
map<string, int>essay;
string s, s1, s2;
int t = 0;
//处理文章
while (t < n) {
getline(cin, s);
ori.push_back(s);
for (int j = 0; j < s.size(); j++) {
if (isalpha(s[j])) s[j] = tolower(s[j]);
else s[j] = ' ';
}
stringstream ss(s);
set<int>st;
while (ss >> s1) {
st.insert(id(s1));
}
k[t].push_back(st);
t++;
}
t = 0;
//处理指令
while (t < m) {
getline(cin, s);
if (s.front() == 'N') {
s1 = s.substr(4);
find_print(s1);
}
else if (s.find(' ') == string::npos) {
find_print(s);
}
else {
string::iterator it = s.begin();
advance(it, s.find(' '));
if (*it == 'A') {
s1 = s.substr(0, s.find(' '));
s2 = s.substr(s.find(' ') + 4);
find_print1(s1, s2);
}
else {
s1 = s.substr(0, s.find(' '));
s2 = s.substr(s.rfind(' '));
find_print2(s1, s2);
}
}
}
return 0;
}