题解 | #数据分类处理#
数据分类处理
https://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
bool isIncluded(const int& y, const int& x){
string str_x = to_string(x);
string str_y = to_string(y);
for(int i = 0; i < str_y.size(); ++i){
int ori = i;
int j = 0;
while(i < str_y.size() && j < str_x.size() && str_y[i] == str_x[j]){
++i;
++j;
}
if(j == str_x.size()){
return true;
}
i = ori;
}
return false;
}
int main(int argc, char* argv[]){
int I_N;
cin >> I_N;
vector<int> I(I_N, 0);
for(int i = 0; i < I_N; ++i){
cin >> I[i];
}
int R_N;
cin >> R_N;
set<int> dic;
int R_value;
while(cin >> R_value){
dic.insert(R_value);
}
vector<vector<int>> res;
int count = 0;
for(int R_num : dic){
vector<int> curr(2, 0);
curr[0] = R_num;
for(int i = 0; i < I_N; ++i){
if(isIncluded(I[i], R_num)){
curr[1] += 1;
curr.push_back(i);
curr.push_back(I[i]);
}
}
int curr_size = curr.size();
if(curr_size > 2){
res.push_back(curr);
count += curr_size;
}
}
cout << count << " ";
for(auto i : res){
for(int j : i){
cout << j << " ";
}
}
cout << endl;
return 0;
}